#11936: Proxy models' names are too long for django.contrib.auth which causes
weird
test failures
---------------------------------------------------+------------------------
Reporter: ryszard | Owner: clamothe
Status: new | Milestone:
Component: Database layer (models, ORM) | Version: 1.1
Resolution: | Keywords: test,
only, deferred fields
Stage: Unreviewed | Has_patch: 1
Needs_docs: 0 | Needs_tests: 0
Needs_better_patch: 0 |
---------------------------------------------------+------------------------
Comment (by clamothe):
Yes, I added the correct patch. I will explain how it fixes the problem
for me.
= The problem =
If the following sounds like gibberish then read the background info
first.
In the aftermath of a query that used `QuerySet`'s `defer()` or `only()`
methods, a ''deferred model'' could exist. Without my patch, the results
of the `django.db.models.loading.get_models` method include deferred
models. With my patch, the results of this method do not include
''deferred models''.
If ''deferred models'' are included in the results of this method then
they could be mistaken for real models. An example of of such is when
`django.contrib.auth` autopopulates it's permission table. Certainly
creating separate permissions for ''deferred models'' is not intended.
Additionally, the name of the deferred model's class might not fit in the
50 characters allowed in `Permission`'s `name` field, causing a database
error or warning such as:
{{{
Warning: Data truncated for column 'name' at row 1
}}}
= Background information =
When QuerySet's defer() or only() methods are used in a query, django
dynamically creates a model that includes only the fields that the
QuerySet needs. If `User.objects.only('username', 'password')` is called
then django will create a special ''deferred'' `User` model that only
includes the username and password fields. Django would call this model
`User_Deferred_username_password`. If a model has many fields and one or
two fields are deferred in a query then the name of the ''deferred model''
created for the queryset can be very long, as it includes the names of
each field that will be retrieved.
Keep that in mind while we jump over to `django.contrib.auth`. This app
creates the permissions for each installed model whenever the database is
reset or syncdb is called. Remember the model permissions that you can
assign to Users and Groups when using the admin? This is where those
permissions are created. The method that creates these permissions first
looks up each installed model, using django.db.models.loading.get_models
to get the installed models, then creates the `Permission` objects for
each installed model. Each `Permission` object is assigned a `name`. The
`name` field contains a description of the permission (i.e. "Can add
Group") and has a `max_length` of 50.
--
Ticket URL: <http://code.djangoproject.com/ticket/11936#comment:6>
Django <http://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 post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.