Skip to content

Conversation

@takechanman1228
Copy link

This PR fixes a bug where TinyPersonFactory crashes with a TypeError when logging level is set to INFO or DEBUG in config.ini. ( Issue: #140 )

Error message:

TypeError: Object of type set is not JSON serializable

Root Cause

The issue occurs in 4 locations in tiny_person_factory.py where json.dumps() is used for debug logging:

  1. Line 300 - generate_person(): Generated person parameters
  2. Line 532 - _initialize_sampling_plan_transaction(): Sampling dimensions
  3. Line 548 - _initialize_sampling_plan_transaction(): Sampling plan
  4. Line 562 - _initialize_sampling_plan_transaction(): Remaining characteristics sample

All of these data structures may contain Python set objects (likely used for deduplication/uniqueness), which are not JSON serializable by default.

Changes

Added:

  • _safe_json_dumps() helper function (after line 21). This function converts set objects to list before serialization, preserving the debug output while avoiding the crash.

Modified (4 locations):

  • Line 300: generate_person() - Use _safe_json_dumps() for person parameters
  • Line 532: _initialize_sampling_plan_transaction() - Use _safe_json_dumps() for sampling dimensions
  • Line 548: _initialize_sampling_plan_transaction() - Use _safe_json_dumps() for sampling plan
  • Line 562: _initialize_sampling_plan_transaction() - Use _safe_json_dumps() for remaining characteristics

@takechanman1228
Copy link
Author

@microsoft-github-policy-service agree

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