Skip to content

Commit cc359f3

Browse files
committed
Refactor Paddle customer metadata synchronization to safely handle custom data extraction and improve error logging
1 parent 40438b4 commit cc359f3

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

src/backend/base/langflow/services/paddle/subscriptions.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,22 +186,37 @@ async def _sync_paddle_customer_metadata(
186186
customer: Any,
187187
clerk_user_id: str,
188188
) -> None:
189-
existing_custom_data = dict(getattr(customer, "custom_data", None) or {})
189+
# Safely extract the custom data dict from the SDK object
190+
raw_custom_data = getattr(customer, "custom_data", None)
191+
192+
if raw_custom_data is None:
193+
existing_custom_data = {}
194+
elif isinstance(raw_custom_data, dict):
195+
existing_custom_data = raw_custom_data
196+
else:
197+
# Extract the internal dict from the custom data object
198+
existing_custom_data = dict(raw_custom_data.data)
199+
200+
# If metadata already matches, no need to update
190201
if str(existing_custom_data.get(PADDLE_CUSTOM_DATA_USER_ID_KEY, "")).strip() == str(clerk_user_id):
191202
return
192203

204+
# Prepare updated data
193205
updated_custom_data = dict(existing_custom_data)
194206
updated_custom_data[PADDLE_CUSTOM_DATA_USER_ID_KEY] = str(clerk_user_id)
207+
208+
# Send update request via Paddle API
195209
try:
196210
await asyncio.to_thread(
197211
client.customers.update,
198212
customer.id,
199213
UpdateCustomer(custom_data=CustomData(updated_custom_data)),
200214
)
201-
except Exception as exc: # noqa: BLE001
215+
except Exception:
202216
logger.exception(
203217
"Failed to sync Paddle customer metadata for customer %s and clerk user %s.",
204218
customer.id,
205219
clerk_user_id,
206220
)
207221
raise
222+

0 commit comments

Comments
 (0)