Opened 2 years ago

Closed 2 years ago

#19944 closed Bug (fixed)

django 1.5 is not compatible with pypy 1.9 because of django.test._doctest

Reported by: kmike Owned by: aaugustin
Component: Python 2 Version: 1.5
Severity: Normal Keywords: pypy
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Latest released pypy (1.9) doesn't provide __globals__ attribute and this attribute was introduced in process of making django.test._doctest Python 3.x compatible in this commit: https://github.com/django/django/commit/f1d5dc81ac37fe9a7c7ca860900ee6a16150bb09. It causes tests (of external django apps) to fail when executed under pypy 1.9 with django 1.5 (with an unhelpful AttributeError: 'function' object has no attribute '__globals__' error without a stack trace).

Example: https://travis-ci.org/kmike/django-webtest/jobs/5097045

I think there should be a fallback to func_globals if __globals__ is not available.

Change History (12)

comment:1 Changed 2 years ago by kmike

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

It is not necessary for test suite to include doctests to become incompatible with django 1.5 & pypy 1.9.

comment:2 Changed 2 years ago by aaugustin

__globals__ isn't documented for Python 2.x; I'm surprised the bug occurs under PyPy and not Python 2.x. I don't remember exactly what I checked before making this commit.

comment:3 Changed 2 years ago by kmike

  • Has patch set

Pull request: https://github.com/django/django/pull/869

There are similar "dangerous" attributes: "__code__", "__closure__", "__defaults__", "__func__" and "__self__" .

"__globals__" and "__code__" are fixed in this pull request.

"__closure__" and "__defaults__" are not used in django; "__func__" and "__self__" are mentioned in Python 2.6 release notes so it should be fine to use them.

comment:4 Changed 2 years ago by jacob

  • Triage Stage changed from Unreviewed to Accepted

comment:5 Changed 2 years ago by aaugustin

Now I remember. I was sloppy for this module. I skimmed Vinay Sajip's patch and applied it.

Obviously I should have re-done the porting myself, like I did for every other module in Django.

comment:6 Changed 2 years ago by aaugustin

  • Owner changed from nobody to aaugustin
  • Status changed from new to assigned

I filed an issue against six to figure out whether this is an oversight in six or whether there's a better alternative:
https://bitbucket.org/gutworth/six/issue/21/additional-object-model-compatibility

comment:7 Changed 2 years ago by aaugustin

  • Component changed from Testing framework to Python 2

comment:8 Changed 2 years ago by aaugustin

Benjamin added the functions we needed to six. I'm going to update the bundled version of six and then fix this.

comment:9 Changed 2 years ago by Aymeric Augustin <aymeric.augustin@…>

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

In 9d4a5b00f1977d8cddf8e241fa4bb8a9e819f188:

Stopped using non-standard globals and code attributes.

Some alternative implementations don't have them.

Closes #19944.

comment:10 Changed 2 years ago by kmike

Thanks!

Could you apply the fixes to 1.5.x as well (pull request was to 1.5.x)? Not being able to run tests == not being able to use PyPy at all, and an inability to use a certain Python interpreter with django is a pretty serious issue IMHO (I'd even call it a release blocker), and this is 1.5 regression.

comment:11 Changed 2 years ago by aaugustin

  • Resolution fixed deleted
  • Status changed from closed to new

I tried backporting the two commits to 1.5 and I got conflicts, I'll fix that later today.

comment:12 Changed 2 years ago by Aymeric Augustin <aymeric.augustin@…>

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

In 1c9bd69ff045cf304fcfe127eac53e8712d33d75:

[1.5.x] Stopped using non-standard globals and code attributes.

Some alternative implementations don't have them.

Closes #19944.

Backport of 9d4a5b00f1977d8cddf8e241fa4bb8a9e819f188 from master.

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