1. fiji
  2. django-3k
  3. Issues
Issue #64 resolved

Resolve 'return key in self' max recursion error in test_has_key

g8mjg
created an issue

Several hundred lines of

"File "C:\python31\lib\site-packages\django\core\cache\backends\base.py", line 93, in contains return key in self" in test suite output and a complaint about max recursion depth. Causing an unknown number of errors.

Being handled by subgroup 3.

Comments (5)

  1. g8mjg reporter

    Fixed. fix_dict was overwriting all calls to has_key, so it was rewriting everything with .has_key. core\cache\backends\base.py includes a contains method which simply returned self.has_key to prevent overwriting. Changing the return to the same as has_key preserves this functionality and stops 2to3 from writing over this and breaking it.

  2. Martin von Löwis
    • changed status to open

    I think the patch is inappropriate. The comment above the modified line explicitly states

    "This is a separate method, rather than just a copy of has_key()"

    Now, with your change, the code is a copy of has_key, even though it promises that it isn't.

    If the problem is that 2to3 replaces the has_key call, it may be necessary to trick it into not doing that; the simplest work-around would be

      return getattr(self, 'has_key')(key)
    

    It may be ok to require Django applications on 3.x to override contains instead/in addition to overriding has_key; if that approach is taken, doing

      if sys.version_info<(3,):
         return self.has_key(key)
      return self.get(key) is None
    

    would be appropriate. In that case, the assumption that overriding has_key is not supported on 3.x would have to be documented somewhere.

  3. Log in to comment