#17653: using id = 0 on get_or_create -------------------------------------+------------------------------------- Reporter: sylvain.lebon@… | Owner: nobody Type: Bug | Status: new Component: Database layer | Version: 1.3 (models, ORM) | Resolution: Severity: Normal | Triage Stage: Accepted Keywords: | Needs documentation: 0 Has patch: 1 | Patch needs improvement: 0 Needs tests: 0 | UI/UX: 0 Easy pickings: 0 | -------------------------------------+------------------------------------- Changes (by krzysiumed):
* owner: krzysiumed => nobody * needs_better_patch: 1 => 0 * status: assigned => new Comment: Sorry for delay, but the ticket is not as easy as I thought. 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. I'm not sure if `get_db_prep_save` is right place for validation. The doc of the method says: {{{ Returns field's value prepared for interacting with the database backend. Used by the default implementations of ``get_db_prep_save``and `get_db_prep_lookup``` }}} so maybe we should add note that `get_db_prep_save` do validation and may raise error? 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). -- Ticket URL: <https://code.djangoproject.com/ticket/17653#comment:11> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To post to this group, send email to django-updates@googlegroups.com. To unsubscribe from this group, send email to django-updates+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-updates?hl=en.