Opened 12 years ago
Closed 12 years ago
#19069 closed Cleanup/optimization (fixed)
improve error when attempting to use a swapped model
Reported by: | Preston Holmes | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 1.4 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Currently two checks for a swapped model exist when creating a manager:
- https://github.com/django/django/blob/3b6f980bedbbf091fe29bececa2b262d2084ce4d/django/db/models/manager.py#L16
- https://github.com/django/django/blob/3b6f980bedbbf091fe29bececa2b262d2084ce4d/django/db/models/manager.py#L61
These result in an error:
AttributeError: type object 'User' has no attribute 'objects'
as opposed to DatabaseError: no such table: <...>
which is the error when the model is swapped but has the default manager (as syncdb will not create tables for swapped models). Ideally - there should be a manager installed that just raises an error explaining that the model has been swapped and is unavailable and probably offer information about what model it was swapped for - as this is readily available.
In cc337a74f1808b216fff96f1695d8b066d2636f6: