﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
662	saving a newly created object without any data causes an error	Adam Endicott <leftwing17@…>	Adrian Holovaty	"This is best explained with an example:

{{{
#!python
class Poll(meta.Model):
    name = meta.CharField(maxlength=100, blank=True)
}}}

{{{
>>> from django.models.myProject import polls
>>> p = polls.Poll()
>>> p.save()
Traceback (most recent call last):
  File ""<stdin>"", line 1, in ?
  File ""c:\progra~1\python23\lib\site-packages\django\utils\functional.py"", line
 3, in _curried
    return args[0](*(args[1:]+moreargs), **dict(kwargs.items() + morekwargs.item
s()))
  File ""c:\progra~1\python23\lib\site-packages\django\core\meta\__init__.py"", li
ne 783, in method_save
    pk_val = getattr(self, opts.pk.column)
AttributeError: 'Poll' object has no attribute 'id'
>>> c = companies.Company(name='something')
>>> c.save()
>>> (no error)
}}}
I think the problem (if this is considered a problem) comes in django/core/meta/!__init!__.py in the method_init method. If kwargs are supplied to the !__init!__, every field in the object is set to some value, including the id !AutoField. If there are no kwargs, the id field isn't set, and you get an error in save(). I don't know the best way to fix this. Removing the {{{if kwargs}}} check at the start of method_init gets rid of the error, but its probably not what's desired. Maybe an explicit check at the end that id (or any !AutoFields) have been set?"	defect	closed	Core (Other)		normal	fixed			Unreviewed	0	0	0	0	0	0
