Opened 17 years ago

Closed 17 years ago

Last modified 17 years ago

#5191 closed (invalid)

Handle "None" when type is <type: 'str'>

Reported by: Ari Kivimäki <arinium@…> Owned by: Adrian Holovaty
Component: Database layer (models, ORM) Version: dev
Severity: Keywords: None NoneType str String
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Apparently at least pysqlite 2.3.5 (with Python 2.5) returns "None" (<type: 'str'>) instead of None (<type: 'NoneType'>) when a field is NULL. This causes problems with Django when conditional statement compares solely to NoneType and passes string values. Fortunately this is easily fixed: if the conditional statement (if not s: return None) on db/backends/util.py line 73 is added another condition to satisfy str type "None" (if not s or s == "None": return None).

Change History (3)

comment:1 by Malcolm Tredinnick, 17 years ago

Resolution: invalid
Status: newclosed

I don't think you are diagnosing the right problem here. Python 2.5's built-in SQLite wrapper does not return the string "None" in these cases. I have a lot of models lying around with NULL entries and Python 2.5 returns them all correctly (using Django's current code).

Use the sqlite3 command line tool to have a look at your database tables. I think you will find they contain the string "None" for some reason.

comment:2 by Ari Kivimäki <arinium@…>, 17 years ago

You are correct. There was indeed one entry that for some reason had "None" instead of a valid value. Thank you very much, problem solved.

comment:3 by Ari Kivimäki <arinium@…>, 17 years ago

For some reason this problem did not occur before I updated my system to Python 2.5, therefor I was hesitant to blame upgraded pysqlite.

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