Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#14691 closed (fixed)

foreign key validate() fails for non-default databases

Reported by: marcop Owned by: nobody
Component: Database layer (models, ORM) Version: master
Severity: Keywords: validation, foreign key, mutiple_database
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

to reproduce:

  1. configure two databases: default and other
  2. have two models Person and Pet:
    class Person(models.Model):
        name = models.CharField(max_length=100)
    
    class Pet(models.Model):
        name = models.CharField(max_length=100)
        owner = models.ForeignKey(Person)
    
  3. create Person instance named person in database 'other'
  4. create Pet instance named pet in database 'other'
  5. try calling pet.full_clean() or, more specifically, pet._meta.get_field('owner').validate(person.pk, person)

patch and test attached

Attachments (3)

multidb_foreignkey_validation_patch.diff (796 bytes) - added by marcop 5 years ago.
multidb_management_tests.diff (1.8 KB) - added by marcop 5 years ago.
14691.diff (1.6 KB) - added by ramiro 5 years ago.
Patch with tests

Download all attachments as: .zip

Change History (7)

Changed 5 years ago by marcop

Changed 5 years ago by marcop

Changed 5 years ago by ramiro

Patch with tests

comment:1 Changed 5 years ago by ramiro

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

Seems multidb_management_tests.diff you a attached are actually tests for other ticket you opened #14662.

Attached another patch that only adds tests.

comment:2 Changed 5 years ago by mpaolini

oh thanks. My bad.

The bug also affects 1.2

comment:3 Changed 5 years ago by ramiro

  • Resolution set to fixed
  • Status changed from new to closed

(In [14580]) Fixed #14691 -- Made ForeignKey.validate() use the right database. Thanks Marco Paolini for the report.

comment:4 Changed 5 years ago by ramiro

(In [14581]) [1.2.X] Fixed #14691 -- Made ForeignKey.validate() use the right database. Thanks Marco Paolini for the report.

Backport of [14580] from trunk

Note: See TracTickets for help on using tickets.
Back to Top