Opened 4 years ago

Closed 4 years ago

Last modified 22 months ago

#15866 closed Bug (fixed)

get_model() and get_models() can return models that are not in INSTALLED_APPS

Reported by: carljm Owned by: carljm
Component: Database layer (models, ORM) Version:
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX:


register_models() does not check if the app is present in INSTALLED_APPS, and so importing a file will cause that apps' models to be available via get_model() or get_models(), even though the app is not installed (meaning it has no database tables, so actually using those models is almost certain to cause a database error).

Change History (7)

comment:1 Changed 4 years ago by carljm

  • Needs documentation unset
  • Needs tests unset
  • Owner changed from nobody to carljm
  • Patch needs improvement unset
  • Status changed from new to assigned
  • Triage Stage changed from Unreviewed to Accepted

comment:2 Changed 4 years ago by carljm

#15850 is the most immediately problematic symptom of this bug.

comment:3 Changed 4 years ago by carljm

  • Has patch set

Candidate fix for this with test here:

comment:4 Changed 4 years ago by carljm

  • Resolution set to fixed
  • Status changed from assigned to closed

In [16053]:

(The changeset message doesn't reference this ticket)

comment:5 follow-up: Changed 4 years ago by jezdez

  • Easy pickings unset

This should really have been added to the app-loading branch, not trunk.

comment:6 in reply to: ↑ 5 Changed 4 years ago by carljm

Replying to jezdez:

This should really have been added to the app-loading branch, not trunk.

I don't mind porting this fix to app-loading branch, but fixing it in trunk resolved a problematic regression (#15850) which prevented reusable app authors from running their tests against trunk. I wouldn't want to delay that fix until app-loading lands, though if having this in trunk is a serious problem we could temporarily use a hackier workaround to resolve #15850.

comment:7 Changed 22 months ago by Aymeric Augustin <aymeric.augustin@…>

In 9f13c3328199d2fa70235cdc63bb06b1efc5b117:

Removed the only_installed argument of Apps.get_models.

Refs #15903, #15866, #15850.

Note: See TracTickets for help on using tickets.
Back to Top