Opened 5 years ago

Closed 5 years ago

#17256 closed Bug (fixed)

ContentTypeManager.get_by_natural_key method doesn't cache

Reported by: defaultwombat Owned by: nobody
Component: contrib.contenttypes Version: 1.3
Severity: Normal Keywords: cache contenttypes
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

django.contrib.contenttypes.models.py
ContentTypeManager.get_by_natural_key

Code highlighting:

  def get_by_natural_key(self, app_label, model):
      try:
          ct = self.__class__._cache[self.db][(app_label, model)]
      except KeyError:
          ct = self.get(app_label=app_label, model=model)
      return ct

If the content_type is not in the cache yet, the method uses get() without adding the result to the cache.

I cannot see how #16042 could be solved without fixing this.

Attachments (3)

17107.patch (502 bytes) - added by defaultwombat 5 years ago.
patch for svn r17107
ticket-17256-with-tests.diff (2.6 KB) - added by Simon Charette 5 years ago.
Updated patch with tests
master...ticket-17256-contentypemanager-get_by_natural_key-doesnt-cache.diff (4.4 KB) - added by Simon Charette 5 years ago.

Download all attachments as: .zip

Change History (10)

Changed 5 years ago by defaultwombat

Attachment: 17107.patch added

patch for svn r17107

comment:1 Changed 5 years ago by Luke Plant

Needs tests: set
Triage Stage: UnreviewedAccepted

Changed 5 years ago by Simon Charette

Updated patch with tests

comment:2 Changed 5 years ago by Simon Charette

Needs tests: unset

Added tests

comment:3 Changed 5 years ago by Simon Charette

Added a new patch which corrects tests introduced for #16042 in r16737 to actually test that calls to get_by_natural_key cache the ct instead of simulating cache using get_for_model.

The diff is generated from github.

comment:4 Changed 5 years ago by Claude Paroz

Triage Stage: AcceptedReady for checkin

comment:5 Changed 5 years ago by Julien Phalip

Resolution: fixed
Status: newclosed

In [17502]:

Fixed #17256 -- Ensured that content types get cached when retrieved by natural key. Thanks, defaultwombat and charettes.

comment:6 Changed 5 years ago by davide@…

Resolution: fixed
Status: closedreopened
Version: SVN1.3

Any chance for this fix to be backported in 1.3.X?

comment:7 in reply to:  6 Changed 5 years ago by Ramiro Morales

Resolution: fixed
Status: reopenedclosed

Replying to davide@…:

Any chance for this fix to be backported in 1.3.X?

Unfortunately no.

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