Opened 7 years ago

Closed 4 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: master
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@… 7 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 4 years ago.
Same patch, but for django >= 1
7783-3.diff (2.6 KB) - added by claudep 4 years ago.
Patch updated with test

Download all attachments as: .zip

Change History (18)

Changed 7 years ago by bthomas@…

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

comment:1 Changed 7 years ago by mtredinnick

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

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

comment:2 Changed 7 years ago by Bob Thomas <bthomas@…>

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 Changed 7 years ago by Simon Greenhill

  • Patch needs improvement set
  • Triage Stage changed from Unreviewed to Accepted

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

comment:4 Changed 4 years ago by gabrielhurley

  • Component changed from django-admin.py inspectdb to Core (Management commands)

comment:5 Changed 4 years ago by baumer1122

  • Severity set to Normal
  • Type set to Bug

comment:6 Changed 4 years ago by anonymous

  • 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 Changed 4 years ago by anonymous

  • Triage Stage changed from Accepted to Ready for checkin

comment:8 Changed 4 years ago by aaugustin

  • 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 Changed 4 years ago by aaugustin

  • Triage Stage changed from Ready for checkin to Accepted

comment:10 Changed 4 years ago by ricardodani

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.

Changed 4 years ago by ricardodani

Same patch, but for django >= 1

comment:11 Changed 4 years ago by ricardodani

Added patch to version of django > 1.0

comment:12 Changed 4 years ago by ramiro

  • Keywords inspectdb added

Changed 4 years ago by claudep

Patch updated with test

comment:13 Changed 4 years ago by claudep

  • Needs tests unset
  • Patch needs improvement unset

comment:14 Changed 4 years ago by ramiro

  • Triage Stage changed from Accepted to Ready for checkin

comment:15 Changed 4 years ago by ramiro

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

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