Strings which look like numbers are not quoted, MySQL
|Reported by:||anonymous||Owned by:||nobody|
|Component:||Database layer (models, ORM)||Version:||1.0|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
Create a simple model with a CharField.
Create a ModelForm for that model.
The model can be created successfully and saved to the database using CharField data which looks like a number (e.g. IP address), but updating that model using the same ModelForm fails if the data already existing in the database looks like a number.
form = Config(request.POST, instance=mymodel) # A form bound to the POST data if form.is_valid(): # All validation rules pass try: form.save() # Throws blank exception
The SQL query that fails (from db.connection.queries) is:
SELECT .... FROM `service_config` WHERE (`service_config`.`customer_id` = 1 AND `service_config`.`hostname` = 192.168.1.20
The last item should be in quotes. MySQL will fail on this statement, and the Exception returned from ModelFormInstance.save() is blank (printing the exception results in a null string).
Change the data to 'X192.168.1.20' and it works as expected.
This occurs in at least 1.0.1 and 1.0.2.