#1705: If you make an instance of a class without supplying kwargs the result is
an instance with defects.
----------------------------------+-----------------------------------------
Reporter: [EMAIL PROTECTED] | Owner: adrian
Type: defect | Status: new
Priority: normal | Milestone:
Component: Core framework | Version:
Severity: normal | Resolution:
Keywords: |
----------------------------------+-----------------------------------------
Comment (by lukeplant):
ubernostrum,
The problem is that setting a field/value after creating the instance
doesn't fix things up. So for instance, if you have a model with field1,
field2, and field3, this works
{{{
#!python
m = MyModel(field1='foo')
m.field2 = 'bar'
m.save() # field3 will have been set to a default.
}}}
But this doesn't:
{{{
#!python
m = MyModel()
m.field1 = 'foo'
m.field2 = 'bar'
m.save() # Raises an AttributeError
}}}
I've come across this lots of times (especially in my migration scripts
and at the interactive prompt, and always just put up with it till now,
but I would like to see it fixed. Another important use case would be:
{{{
#!python
m = MyModel()
fill_in_core_data(m)
m.save()
...
# MyExtendedModel has similar interface to MyModel
m2 = MyExtendedModel()
fill_in_core_data(m2)
m2.extra_field = 'foo'
m2.save()
}}}
There is an easier and more robust fix than the patch though -- just
remove the {{{if kwargs}}} check.
--
Ticket URL: <http://code.djangoproject.com/ticket/1705>
Django <http://code.djangoproject.org/>
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 [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-updates
-~----------~----~----~----~------~----~------~--~---