Code

Opened 6 years ago

Closed 6 years ago

#7586 closed (invalid)

contenttypes table not created properly

Reported by: sagivmalihi@… Owned by: nobody
Component: Uncategorized Version: master
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description (last modified by mtredinnick)

if i have 2 applications - app1, app2 , both with a sub-module sub:

app1/sub/models.py
app2/sub/models.py

then only models from one of the apps will get a row in the django_contenttypes table.

This is because, when processing app2 - in update_contenttypes (contenttypes/manangement.py) first gets all current contenttypes for app1 (because the query ContentType.objects.filter(app_label=app.__name__.split('.')[-2]) returns all the rows for app1 and app2)
and then after inserting all the objects for app2 (which are not present there) - it deletes all the previous objects inserted for app1 because it thinks they're 'stale' (they weren't part of get_models(app2))

Attachments (0)

Change History (3)

comment:1 Changed 6 years ago by mtredinnick

  • Description modified (diff)
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

(Fixed description formatting somewhat)

Can you please confirm that you have the Meta.app_label attribute set on both these models? And that they are set to different things? If you have models inside subdirectories, app_label must be set, otherwise Django cannot work out the app_name correctly. It sounds like the only reasons that models from both applications are being pulled back is because Django thinks their app names are sub (when they should be app1 and app2).

comment:2 Changed 6 years ago by sagivmalihi@…

perhaps I misunderstand the terminology.
in settings.py i have
INSTALLED_APPS = ('app1.sub', 'app2.sub')
so in this meaning, the 'app name' for them should be app1.sub and app2.sub (both 'sub' modules are apps that may be portable sometime, and it is probably wrong to name them 'app1' and 'app2' respectively in the Meta subclass.
I would expect that contenttypes will store their app_label as app1.sub and app2.sub respectively.

comment:3 Changed 6 years ago by mtredinnick

  • Resolution set to invalid
  • Status changed from new to closed

The application name is only the last part of the path mentioned in INSTALLED_APPS -- the bit after the final period. So in this case, you are trying to install two apps called sub (the earlier pieces of the path are just use to find the right import path).

Sounds like there isn't really a bug in the content-types creation here. Apps must have unique names and it's only the last word that is used to name the app.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.