Skip to content

fix: serialize M2M fields as lists of PKs in list/get responses#77

Open
foogunlana wants to merge 1 commit into7tg:mainfrom
foogunlana:fix/m2m-serialization
Open

fix: serialize M2M fields as lists of PKs in list/get responses#77
foogunlana wants to merge 1 commit into7tg:mainfrom
foogunlana:fix/m2m-serialization

Conversation

@foogunlana
Copy link

Summary

  • Fix PydanticSerializationError when listing/getting models with ManyToMany fields
  • Convert M2M field values to lists of primary keys instead of leaving them as Django model instances
  • Also convert ForeignKey references to PKs instead of strings for consistency

Fixes #76

Test plan

  • Verify that models with M2M fields can be listed and retrieved without errors
  • Verify that M2M field values appear as lists of integer PKs in responses
  • Verify that ForeignKey fields still serialize correctly (now as PKs instead of string representations)
  • Verify that models without M2M fields continue to work as before

🤖 Generated with Claude Code

model_to_dict() returns M2M fields as lists of Django model instances,
which Pydantic cannot serialize, causing PydanticSerializationError.
Convert M2M values to lists of PKs, and FK values to PKs for consistency.
@foogunlana foogunlana force-pushed the fix/m2m-serialization branch from 470c416 to 451a529 Compare March 10, 2026 12:59
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.

M2M fields cause PydanticSerializationError in list/get handlers

1 participant