Opened 12 years ago
Closed 12 years ago
#19197 closed Bug (fixed)
BaseDatabaseOperations: convert_values raise error on None data type conversions
Reported by: | Maximiliano Robaina | Owned by: | |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 1.4 |
Severity: | Normal | Keywords: | |
Cc: | maxirobaina@… | Triage Stage: | Accepted |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
convert_values method of BaseDatabaseOperations, make a explicit convertion to int type on IntegerField (or derived). The value to convert is not checked, then if value is None a TypeError is raised.
TypeError: int() argument must be a string or a number, not 'NoneType'
Similar case on float convertion.
Change History (5)
comment:1 by , 12 years ago
comment:2 by , 12 years ago
Ok, I'll try to explain this:
- Maybe it only happens with database engines that override DatabaseOperations.convert_values and use this method in SQLCompiler.resolve_columns (I'm working on Firebird engine but you can see at Oracle implementation).
- The specific DatabaseOperations.convert_values must to call super from base class (Oracle implementation doesn't do that), then
def convert_values(self, value, field):
value = super(DatabaseOperations, self).convert_values(value, field)
...
# others values conversions
return value
- The problem is exposed on model_fields test app, BigIntegerFieldTests, test_types method
I hope I have made this sufficiently clear.
Let me know if you need more information.
comment:4 by , 12 years ago
Patch available at https://github.com/akaariai/django/compare/ticket_19197
There is a fix for completely unrelated issue in one commit - backends tests seem to leak connections if ran alone on postgresql. This ticket's issue is fixed without tests, the base convert_values() has been doing a different thing than for example sqlite3's convert_values(), so writing a test for just base convert_values() seemed wrong.
In general the situation with convert_values() and Field.to_python is somewhat messy. It would be nice to clean that up but not this ticket's problem...
comment:5 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Could you provide some sample code (or better yet, test case) to show this problem?