OneToOneField is not validated as a required field, nor do explicitly defined isNotEmpty validators fire
|Reported by:||mrmachine <real dot human at mrmachine dot net>||Owned by:||Adrian Holovaty|
|Component:||Database layer (models, ORM)||Version:||master|
|Severity:||Keywords:||OneToOne required validation validators|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
OneToOne field's don't properly validate the requirement that there _must_ be one object on each side of the relationship. after adding a model (Person) with a OneToOne field to User, i can go into the django admin and attempt to create a new person and leave the user field empty. no validation errors are returned (for example, "This is a required field"). if all other fields are valid, an uncaught type mismatch error will bubble up to the surface. i tried explicitly adding my own isNotEmpty validator to the field, but that doesn't seem to trigger, either.
is this just the way things are, and i should use ForeignKey with unique=True? this works, and i can still use u.get_profile() (if i've configured AUTH_PROFILE_MODULE in settings.py, but this doesn't help if i have multiple apps within a project which have their own distinct extensions to User. u.get_profile() will only work for one of them, and only works when extending User, not when extending any model in a OneToOne manner generally, and is also tied to the idea of the extending model being a "profile". imho it would be nice to keep the u.person mapping in the ORM, either by using OneToOne fields (which could just be a ForeignKey with unique=True behind the scenes, plus an extra mapping on the user instance), or by adding some logic to ForeignKey which adds the extra mapping if unique=True.