Uncaught exception in django/db/models/base.py: UnboundLocalError
|Reported by:||HM <hanne.moa@…>||Owned by:||nobody|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
In source:django/trunk/django/db/models/base.py as of , lines 197-203:
for field in fields_iter: rel_obj = None if kwargs: if isinstance(field.rel, ManyToOneRel): try: # Assume object instance was passed in. rel_obj = kwargs.pop(field.name)
If kwargs[field.name] is None, rel_obj is set to None, val is not set at all, and we get an UnboundLocalError at line 226. Context: the model in question had a OneToOneField whose primary_key was not yet set/was set to None and a save() was attempted.
See stacktrace at dpaste: http://dpaste.com/74655/
Either we need to have a better error-message here, for instance mentioning what field is the problem and how it can be fixed, or the code needs to do something sensible.