Skip to content

Conversation

@SmileyChris
Copy link
Owner

Summary

  • Nullable CountryField (with null=True) now returns None instead of Country(code=None) when the database value is NULL
  • Updates type stubs so Country.code is always str (never None)
  • Consistent with how nullable multiple fields already behave

Breaking change

Code that previously checked obj.country.code is None should now check obj.country is None. The common pattern if obj.country: continues to work unchanged.

Fixes #481

Test plan

  • Updated existing null behavior tests
  • All 317 tests pass
  • Full check suite passes (formatting, linting, types, coverage)

When a CountryField has null=True and the database value is NULL,
the descriptor now returns None instead of Country(code=None).

This moves nullability from Country.code (str | None) to the field
access itself (Country | None), resulting in cleaner typing and
consistent behavior with nullable multiple fields.

Fixes #481
When a nullable CountryField returns None (instead of Country(code=None)),
the serializer should handle it explicitly rather than relying on alpha2()
converting 'None' string to empty string.
Verify that nullable CountryField works correctly with GraphQL:
- Returns full Country type when value is present
- Returns null when database value is NULL
Test the full round-trip: save NULL to database, fetch it back, and
serialize. This verifies the descriptor correctly returns None and
the serializer handles it properly.
Add documentation explaining that nullable CountryField now returns None
instead of Country(code=None), with examples and migration guidance.
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.

Can Country.code be None in v8.x?

2 participants