#24231: Regression in availability of `_meta.get_field()` before app registry is
fully populated
-------------------------------------+-------------------------------------
Reporter: carljm | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.7
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by carljm):
Hi pirosb3!
I agree on the doc changes to clarify which methods require a complete app
registry. Not sure about modifying the error - I don't think `Options`
should re-wrap the `AppRegistryError` - I guess the base
`AppRegistryError` could point to the app-loading docs, but that seems
like a separate issue.
Regarding adding new public API, I don't have any problem with using a
list comprehension. The problem I have is that there is currently _no_
public API that can be used before the app registry is fully loaded;
neither `get_field()` nor `get_fields()` is usable. The only option AFAICS
is `_get_fields(reverse=False)` (which is what you use internally as well
when you need to introspect before app cache is ready), but that's private
API.
You may be right that 99% of developers will never hit this issue, but I
am not sure of that. Django provides the `class_prepared` signal as public
API, and basically any use of `class_prepared` will involve working with a
model class before the app registry is fully loaded.
More conceptually speaking, it seems wrong to me that there is no public
API at all to introspect a single model class on its own terms (i.e. only
fields declared on that model class), without relying on the rest of the
system.
Actually, I think the `local_fields` attribute might cover this need well
enough, but it's also currently undocumented/private. So I think maybe
just documenting that would take care of it.
--
Ticket URL: <https://code.djangoproject.com/ticket/24231#comment:3>
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].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/064.12eabc5fe3adc5d22c636e2f581b7ed1%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.