Opened 12 years ago

Closed 12 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 12 years ago.
patch for svn r17107
ticket-17256-with-tests.diff (2.6 KB ) - added by Simon Charette 12 years ago.
Updated patch with tests
master...ticket-17256-contentypemanager-get_by_natural_key-doesnt-cache.diff (4.4 KB ) - added by Simon Charette 12 years ago.

Download all attachments as: .zip

Change History (10)

by defaultwombat, 12 years ago

Attachment: 17107.patch added

patch for svn r17107

comment:1 by Luke Plant, 12 years ago

Needs tests: set
Triage Stage: UnreviewedAccepted

by Simon Charette, 12 years ago

Updated patch with tests

comment:2 by Simon Charette, 12 years ago

Needs tests: unset

Added tests

comment:3 by Simon Charette, 12 years ago

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 by Claude Paroz, 12 years ago

Triage Stage: AcceptedReady for checkin

comment:5 by Julien Phalip, 12 years ago

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 by davide@…, 12 years ago

Resolution: fixed
Status: closedreopened
Version: SVN1.3

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

in reply to:  6 comment:7 by Ramiro Morales, 12 years ago

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