Changes between Initial Version and Version 1 of Ticket #17653, comment 11
- Timestamp:
- Feb 13, 2012, 2:55:46 PM (13 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #17653, comment 11
initial v1 1 1 Sorry for delay, but the ticket is not as easy as I thought. 2 2 3 I attached a patch similar to akaariai's patch. It validates value for primary key in new method `BaseDatabaseOperations. check_autopk_value` in module `db.backends`. The method is overriden in `DatabaseOperations` in module `db.backends.mysql`, so it does not use `allows_primary_key_0` flag. The method is called by `AutoField.get_db_prep_value` from module `db.models.fields`. The patch includes simple test.3 I attached a patch similar to akaariai's patch. It validates value for primary key in new method `BaseDatabaseOperations.validate_autopk_value` in module `db.backends`. The method is overriden in `DatabaseOperations` in module `db.backends.mysql`, so it does not use `allows_primary_key_0` flag. The method is called by `AutoField.get_db_prep_value` from module `db.models.fields`. The patch includes simple test. 4 4 5 I'm not sure if `get_db_prep_ save` is right place for validation. The doc of the method says:5 I'm not sure if `get_db_prep_value` is right place for validation. The doc of the method says: 6 6 {{{ 7 7 Returns field's value prepared for interacting with the database … … 11 11 `get_db_prep_lookup``` 12 12 }}} 13 so maybe we should add note that `get_db_prep_ save` do validation and may raise error?13 so maybe we should add note that `get_db_prep_prep` do validation and may raise error? 14 14 15 15 Note that both patches (mine and akaariai's) works for `AutoField` as well as for `ForeignKey` and `ManyToManyField`, because related fields calls `AutoField.get_db_prep_value` during executing their `get_db_prep_value` method (see https://code.djangoproject.com/browser/django/trunk/django/db/models/fields/related.py#L962).