Code

Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#5191 closed (invalid)

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

Reported by: Ari Kivimäki <arinium@…> Owned by: adrian
Component: Database layer (models, ORM) Version: master
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: UI/UX:

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).

Attachments (0)

Change History (3)

comment:1 Changed 7 years ago by mtredinnick

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to invalid
  • Status changed from new to closed

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 Changed 7 years ago by Ari Kivimäki <arinium@…>

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 Changed 7 years ago by Ari Kivimäki <arinium@…>

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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.