-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
Set up serializer fields lazily on-demand. #1963
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
The "test" here is a bit ugly, since it's hard to effectively test these global-state-setup issues. I'm importing and instantiating a model serializer (with fields) in the I'm not sure how else to effectively test this, but I'll happily remove that "test" if it's considered too ugly. |
Thanks a lot. This will definitively help developers porting to Django 1.7. |
@xordoquy Yes, |
Oh, I should explicitly note too that I had to modify a couple other tests asserting that field-configuration errors would be raised on model instantiation, to instead assert that those errors would be raised on first access of the |
One other note - the app-registry errors may still bite anyone who accesses |
# called, to ensure that model serializers don't eagerly configure fields. | ||
from .serializers import ModelSerializerWithFields | ||
ModelSerializerWithFields() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I'd rather just drop this. The hackery required to hard-test the behaviour doesn't seem worth the trade-off.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, force-pushed a new single commit without the test hackery.
Looks like we'd need a bit of minor tweaking of 3.0 to support this, but nothing problematic. |
This avoids AppRegistryNotReady problems in Django 1.7 with nested serializers, which are instantiated at import time, possibly before Django's app registry is fully populated.
Marginally more involved in 3.0 to do this, but resolved there now. |
Set up serializer fields lazily on-demand.
This avoids AppRegistryNotReady problems in Django 1.7 with nested serializers,
which are instantiated at import time, possibly before Django's app registry is
fully populated.
Fixes #1907 and #1943.