[Django] #24290: postgres_tests fail ungracefully if psycopg2 isn't installed

77 views
Skip to first unread message

Django

unread,
Feb 6, 2015, 7:24:33 AM2/6/15
to django-...@googlegroups.com
#24290: postgres_tests fail ungracefully if psycopg2 isn't installed
------------------------------------------------+------------------------
Reporter: aaugustin | Owner:
Type: Cleanup/optimization | Status: new
Component: contrib.postgres | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------------+------------------------
Uninstalling psycopg2 and running `./runtests.py postgres_tests` shows a
series of stack traces.

Would it be possible to make the imports conditional and skip the tests
cleanly?

See `template_backends/test_jinja2.py` for an example.

--
Ticket URL: <https://code.djangoproject.com/ticket/24290>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Feb 6, 2015, 7:49:08 AM2/6/15
to django-...@googlegroups.com
#24290: postgres_tests fail ungracefully if psycopg2 isn't installed
--------------------------------------+------------------------------------

Reporter: aaugustin | Owner:
Type: Cleanup/optimization | Status: new
Component: contrib.postgres | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by timgraham):

* easy: 0 => 1
* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/24290#comment:1>

Django

unread,
Feb 8, 2015, 3:37:27 AM2/8/15
to django-...@googlegroups.com
#24290: postgres_tests fail ungracefully if psycopg2 isn't installed
-------------------------------------+-------------------------------------
Reporter: aaugustin | Owner:
Type: | joelburton
Cleanup/optimization | Status: assigned
Component: contrib.postgres | Version: master

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by joelburton):

* status: new => assigned
* owner: => joelburton
* has_patch: 0 => 1


Comment:

Added conditional import for psycopg2 and @skipIf on tests.

--
Ticket URL: <https://code.djangoproject.com/ticket/24290#comment:2>

Django

unread,
Feb 11, 2015, 12:53:47 PM2/11/15
to django-...@googlegroups.com
#24290: postgres_tests fail ungracefully if psycopg2 isn't installed
-------------------------------------+-------------------------------------
Reporter: aaugustin | Owner:
Type: | joelburton
Cleanup/optimization | Status: assigned
Component: contrib.postgres | Version: master
Severity: Normal | Resolution:
Keywords: 1.8 | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* keywords: => 1.8
* needs_better_patch: 0 => 1
* easy: 1 => 0


Comment:

There is a new problem on master (which affects 1.8 too, but it's a
`RemovedInDjango19Warning` instead of a `RuntimeError`:
{{{
$ ./runtests.py postgres_tests
...
Model class postgres_tests.models.IntegerArrayModel doesn't declare
an explicit app_label and either isn't in an application in INSTALLED_APPS
or else was imported before its application was loaded.
}}}
It's caused by the
[https://github.com/django/django/blob/8ec306a3a90aa2ec0baa4c9d8df68f0d49947a2c/tests/runtests.py#L87-L88
hack in runtests.py] to omit the `postgres_tests` app when not running
with a postgresql database (to avoid trying to apply the migrations when
not in postgresql). I'm attaching a patch I experimented with, but there
are still unsolved problems with it.

--
Ticket URL: <https://code.djangoproject.com/ticket/24290#comment:3>

Django

unread,
Feb 12, 2015, 9:15:51 AM2/12/15
to django-...@googlegroups.com
#24290: postgres_tests fail ungracefully if psycopg2 isn't installed
-------------------------------------+-------------------------------------
Reporter: aaugustin | Owner:
Type: | joelburton
Cleanup/optimization | Status: assigned
Component: contrib.postgres | Version: master

Severity: Normal | Resolution:
Keywords: 1.8 | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by claudep):

Also encountered:
{{{
File "/home/claude/virtualenvs/djangogit/local/lib/python2.7/site-
packages/django/contrib/postgres/forms/ranges.py", line 1, in <module>
from psycopg2.extras import DateRange, DateTimeTZRange, NumericRange
ImportError: cannot import name DateRange
}}}
{{{
>>> psycopg2.__version__
'2.4.5 (dt dec mx pq3 ext)'
}}}
It might also depend on installed PostgreSQL extensions.

--
Ticket URL: <https://code.djangoproject.com/ticket/24290#comment:4>

Django

unread,
Feb 12, 2015, 2:57:59 PM2/12/15
to django-...@googlegroups.com
#24290: postgres_tests fail ungracefully if psycopg2 isn't installed
-------------------------------------+-------------------------------------
Reporter: aaugustin | Owner:
Type: | joelburton
Cleanup/optimization | Status: assigned
Component: contrib.postgres | Version: master

Severity: Normal | Resolution:
Keywords: 1.8 | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by claudep):

Created #24335 for the `DateRange` import failure.

--
Ticket URL: <https://code.djangoproject.com/ticket/24290#comment:5>

Django

unread,
Feb 16, 2015, 11:08:55 AM2/16/15
to django-...@googlegroups.com
#24290: postgres_tests fail ungracefully if psycopg2 isn't installed
-------------------------------------+-------------------------------------
Reporter: aaugustin | Owner:
Type: | joelburton
Cleanup/optimization | Status: assigned
Component: contrib.postgres | Version: master

Severity: Normal | Resolution:
Keywords: 1.8 | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by timgraham):

After looking into this a bit more (trying to remove the hack in
`runtests.py`), I think it might be a better use of time to just skip
`postgres_tests` entirely when not testing with the
`django.db.backends.postgresql_psycopg2` backend. While it's nice in
theory to allow executing the non-database tests while testing with other
backends, in practice it seems quite convoluted. Objections?

Maybe a separate test app (without any models) would be the way to go if
there's a strong incentive to allow that.

--
Ticket URL: <https://code.djangoproject.com/ticket/24290#comment:6>

Django

unread,
Feb 16, 2015, 6:36:23 PM2/16/15
to django-...@googlegroups.com
#24290: postgres_tests fail ungracefully if psycopg2 isn't installed
-------------------------------------+-------------------------------------
Reporter: aaugustin | Owner:
Type: | joelburton
Cleanup/optimization | Status: assigned
Component: contrib.postgres | Version: master
Severity: Normal | Resolution:
Keywords: 1.8-beta | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* keywords: 1.8 => 1.8-beta
* needs_better_patch: 1 => 0


Comment:

[https://github.com/django/django/pull/4157 PR] to skip `postgres_tests`
if not running with PostgreSQL.

--
Ticket URL: <https://code.djangoproject.com/ticket/24290#comment:7>

Django

unread,
Feb 17, 2015, 6:35:19 AM2/17/15
to django-...@googlegroups.com
#24290: postgres_tests fail ungracefully if psycopg2 isn't installed
-------------------------------------+-------------------------------------
Reporter: aaugustin | Owner:
Type: | joelburton
Cleanup/optimization | Status: closed
Component: contrib.postgres | Version: master
Severity: Normal | Resolution: fixed

Keywords: 1.8-beta | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"8b39f33d78ce5749f8ca40a7ae6823b5f6c26c09"]:
{{{
#!CommitTicketReference repository=""
revision="8b39f33d78ce5749f8ca40a7ae6823b5f6c26c09"
Fixed #24290 -- Skipped postgres_tests if not running with PostgreSQL.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/24290#comment:8>

Django

unread,
Feb 17, 2015, 6:36:43 AM2/17/15
to django-...@googlegroups.com
#24290: postgres_tests fail ungracefully if psycopg2 isn't installed
-------------------------------------+-------------------------------------
Reporter: aaugustin | Owner:
Type: | joelburton
Cleanup/optimization | Status: closed
Component: contrib.postgres | Version: master

Severity: Normal | Resolution: fixed
Keywords: 1.8-beta | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"a00a0f880485e1f122e48e0216d34d08efe199e1"]:
{{{
#!CommitTicketReference repository=""
revision="a00a0f880485e1f122e48e0216d34d08efe199e1"
[1.8.x] Fixed #24290 -- Skipped postgres_tests if not running with
PostgreSQL.

Backport of 8b39f33d78ce5749f8ca40a7ae6823b5f6c26c09 from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/24290#comment:9>

Reply all
Reply to author
Forward
0 new messages