Opened 16 years ago

Closed 13 years ago

#7783 closed Bug (fixed)

PostgreSQL database introspection does not detect NULL columns

Reported by: bthomas@… Owned by: nobody
Component: Core (Management commands) Version: dev
Severity: Normal Keywords: inspectdb
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

cursor.description does not return the null_ok field, so database introspection does not add null=True to column definitions. The is_nullable column in information_schema.columns does contain this information, however.

Attachments (3)

pgnulls.diff (1022 bytes ) - added by bthomas@… 16 years ago.
Patch to map the is_nullable column from information_schema to the null_ok item in cursor.description
pgnulls_django1.diff (689 bytes ) - added by ricardodani 13 years ago.
Same patch, but for django >= 1
7783-3.diff (2.6 KB ) - added by Claude Paroz 13 years ago.
Patch updated with test

Download all attachments as: .zip

Change History (18)

by bthomas@…, 16 years ago

Attachment: pgnulls.diff added

Patch to map the is_nullable column from information_schema to the null_ok item in cursor.description

comment:1 by Malcolm Tredinnick, 16 years ago

Is this valid for both postgreSQL 7.x and 8.x? We support both.

comment:2 by Bob Thomas <bthomas@…>, 16 years ago

I am only using PostgreSQL 8.x, but I think information_schema was added in PostgreSQL 7.4:

http://www.postgresql.org/docs/7.4/static/information-schema.html

comment:3 by Simon Greenhill, 16 years ago

Patch needs improvement: set
Triage Stage: UnreviewedAccepted

Accepted. Can someone confirm if/what versions of 7.x this works on?

comment:4 by Gabriel Hurley, 14 years ago

Component: django-admin.py inspectdbCore (Management commands)

comment:5 by Peter Baumgartner, 14 years ago

Severity: Normal
Type: Bug

comment:6 by anonymous, 13 years ago

Easy pickings: unset
UI/UX: unset

We tried to setup an environment using PostgreSQL 7.4.30 (the oldest one available for download)[1] to answer your question. Unfortunately when we run manage.py syncdb we received an error message stating that:

"django.db.utils.DatabaseError: function pg_get_serial_sequence("unknown", "unknown") does not exist"

Further research in the django-users mailing list revealed that version 7.4 of PostgreSQL does not contain the function pg_get_serial_sequence.[2] A reply from django core developer Russell Keith-Magee says that in Django version 1.3 support for PostgreSQL 7.4 was abandoned.[3]

[1]http://www.postgresql.org/ftp/source/
[2]http://markmail.org/thread/pf4bmphpsv6m4djl
[3]http://markmail.org/message/tp5czlz3ipy7vd5j

comment:7 by anonymous, 13 years ago

Triage Stage: AcceptedReady for checkin

comment:8 by Aymeric Augustin, 13 years ago

Needs tests: set

This can't be RFC, the patch doesn't even apply:

trunk % patch -p0 < ~/Downloads/pgnulls.diff
patching file django/db/backends/postgresql_psycopg2/introspection.py
Hunk #1 FAILED at 15.
1 out of 1 hunk FAILED -- saving rejects to file django/db/backends/postgresql_psycopg2/introspection.py.rej

comment:9 by Aymeric Augustin, 13 years ago

Triage Stage: Ready for checkinAccepted

comment:10 by ricardodani, 13 years ago

This patch is applied to which version? I have the same problem, but using django 1.3 and postgres_psycopg2 driver and this patch can not be applied, just like aaugustin have reported.

by ricardodani, 13 years ago

Attachment: pgnulls_django1.diff added

Same patch, but for django >= 1

comment:11 by ricardodani, 13 years ago

Added patch to version of django > 1.0

comment:12 by Ramiro Morales, 13 years ago

Keywords: inspectdb added

by Claude Paroz, 13 years ago

Attachment: 7783-3.diff added

Patch updated with test

comment:13 by Claude Paroz, 13 years ago

Needs tests: unset
Patch needs improvement: unset

comment:14 by Ramiro Morales, 13 years ago

Triage Stage: AcceptedReady for checkin

comment:15 by Ramiro Morales, 13 years ago

Resolution: fixed
Status: newclosed

In [17508]:

Fixed #7783 -- Made introspection of nullable columns more robust with Postgres.

Thanks bthomas AT ncorcle DOT com for the report and initial patch, and
Claude Paroz for the final, complete patch.

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