#9649: [bug] invalid attribute value passed form model constructor ------------------------------------------+--------------------------------- Reporter: ales_zoulek | Owner: nobody Status: new | Milestone: Component: Database layer (models, ORM) | Version: 1.0 Keywords: bug model orm foreignkey | Stage: Unreviewed Has_patch: 0 | ------------------------------------------+--------------------------------- '''How to simulate'''
models.py {{{ from django.db import models class CModel(models.Model): x = models.CharField(max_length=20) def __unicode__(self): return self.x class AModel(models.Model): a = models.FloatField() b = models.FloatField() c = models.ForeignKey(CModel) def __unicode__(self): return u"%s" % self.a }}} shell: {{{ In [1]: from t.a import models In [2]: models.AModel(a=23.0, c=None).c_id In [3]: models.AModel(b=23.0, c=None).c_id Out[3]: 23.0 }}} '''Reason''' Invalid if clause in django/db/models/base.py:242 When rel_obj is set to None, but field.null is set to False, the 'val' variable is NOT set in the whole FOR-cycle and thus the previous value gets used. '''Solution''' insead of: {{{ 242 if rel_obj is None and field.null: 243 val = None }}} there should be: {{{ 242 if rel_obj is None: 243 val = None 244 if not field.null: 245 raise TypeError, "Attribute %s could not be null" % field.name }}} -- Ticket URL: <http://code.djangoproject.com/ticket/9649> Django <http://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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-updates?hl=en -~----------~----~----~----~------~----~------~--~---