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

@Potterluo Potterluo force-pushed the bugfix_capture branch 2 times, most recently from 35d59b1 to 38e0951 Compare November 24, 2025 09:43
@Potterluo Potterluo marked this pull request as draft December 8, 2025 02:47
@Potterluo Potterluo marked this pull request as ready for review December 8, 2025 02:49
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