Skip to content

Conversation

@Potterluo
Copy link
Contributor

Title: Enhance Result-Capturing Decorator to Handle Both Single Objects and Lists

Description:

This PR improves the logic of the result-capturing decorator (used in proj_process) to correctly handle two common return patterns:

  • A single result object (e.g., a dictionary, dataclass instance, or custom object)
  • A list of result objects

Previously, the decorator assumed _proj always contained a list. Passing a single object would cause unexpected iteration (e.g., over dictionary keys) or runtime errors.

Changes:

  • Added _ensure_list() utility to normalize input: wraps non-list inputs into a single-item list while preserving actual lists.
  • Enhanced _to_dict() to safely convert common object types (dicts, dataclasses, namedtuples, and regular objects with __dict__) into dictionaries.
  • Updated proj_process to use these utilities, ensuring robust ingestion into the database regardless of whether the source returns one item or many.
  • Improved error messages for clearer debugging when conversion fails.

Test:
img_v3_02sb_571cc892-0dae-49e5-829f-b5052fa2e44g

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant