#20143: Lazy loading of related fields does not work
-------------------------------------+-------------------------------------
Reporter: andreas_pelme | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.5
(models, ORM) | Resolution:
Severity: Normal | Triage Stage:
Keywords: | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by andreas_pelme):
I have created a pull request that fixes these issues by calling
get_model() when it is not yet loaded in `ForeignKey.get_default` and in
`ReverseSingleRelatedObjectDescriptor.__set__`:
https://github.com/django/django/pull/966
`ReverseSingleRelatedObjectDescriptor.__set__` suffers from the same
problem, although it is not really an issue in practice
{{{
from foo.models import Foo
Foo(bar=1234)
}}}
The expected behavior here is to get the `"ValueError: Cannot assign
"1234": "Foo.bar" must be a "Bar" instance."`. The user code is clearly
already broken and this error will probably be fixed in the user code
before this shows up. Nonetheless, it is a bug and it should also be
fixed.
`ReverseSingleRelatedObjectDescriptor.__get__` also references `rel.to`,
but with the `__set__` fix and given that `__get__` can not really be
called before `__set__`, this can likely not be a problem.
`rel.to` is used in other places than these, it is hard to figure out
where it might lead to bugs. The approach in my pull request is to
carefully load models where needed, but it might be a slippery slope... Is
there a better approach altogheter?
All tests pass with the changes in the pull request, but how can this be
tested reliably?
--
Ticket URL: <https://code.djangoproject.com/ticket/20143#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.