AttributeError: 'NoneType' object has no attribute 'dict'

1,592 views
Skip to first unread message

rajasekhar911

unread,
Jul 30, 2009, 10:06:33 AM7/30/09
to sqlalchemy
I am using declarative method to map objects.
I am getting the following error when i try to create the object

My Class is
from sqlalchemy.ext.declarative import declarative_base
DeclarativeBase = declarative_base()
class User(DeclarativeBase):
__tablename__='managed_nodes'
id = Column(String(50), primary_key=True)
username=Column(String(50))

def __init__(self,username = None,id = None):
self.username = username
if not id:
self.id = username
else:
self.id = id

u = User(username='xxx')

Module model.User:63 in __init__
self.username = username

>> self.username = username
Module sqlalchemy.orm.attributes:151 in __set__ view
<< def __set__(self, instance, value):
self.impl.set(instance_state(instance), value, None)

def __delete__(self, instance):
>> self.impl.set(instance_state(instance), value, None)
Module sqlalchemy.orm.attributes:440 in set view
<< old = self.get(state)
else:
old = state.dict.get(self.key, NO_VALUE)

state.modified_event(self, False, old)
>> old = state.dict.get(self.key, NO_VALUE)
AttributeError: 'NoneType' object has no attribute 'dict'

what can be the possible reason??
my sqlalchemy version is 0.5.1 on centos5.2...

Michael Bayer

unread,
Jul 30, 2009, 10:51:30 AM7/30/09
to sqlal...@googlegroups.com
theres nothing about the given code that should cause any issue (and I
tried it on 0.5.1). Upgrade to 0.5.5 in any case and that will almost
certainly resolve the issue.

rajasekhar911

unread,
Jul 31, 2009, 2:44:59 AM7/31/09
to sqlalchemy
i have upgraded to 0.5.5
Now the error changed to
AttributeError: 'NoneType' object has no attribute 'modified_event'
Module sqlalchemy.orm.attributes:150 in __set__ view
<< def __set__(self, instance, value):
self.impl.set(instance_state(instance), instance_dict
(instance), value, None)

def __delete__(self, instance):
>> self.impl.set(instance_state(instance), instance_dict(instance), value, None)
Module sqlalchemy.orm.attributes:447 in set view
<< else:
old = dict_.get(self.key, NO_VALUE)
state.modified_event(dict_, self, False, old)

if self.extensions:
>> state.modified_event(dict_, self, False, old)
AttributeError: 'NoneType' object has no attribute 'modified_event'

it seems instance_state(instance) returns None.

rajasekhar911

unread,
Jul 31, 2009, 3:39:59 AM7/31/09
to sqlalchemy
is it because of lazy initialization?
I have some other attributes in my class which are lazy initialized.
But these are not mapped to columns.

Michael Bayer

unread,
Jul 31, 2009, 9:15:06 AM7/31/09
to sqlal...@googlegroups.com
theres no way to know unless you can illustrate how to reproduce the
issue fully. one hunch is that your mappers are not compiled (try
calling compile_mappers()).

rajasekhar911

unread,
Aug 3, 2009, 12:28:14 AM8/3/09
to sqlalchemy
the error can be reproduced by adding __getattr__ method to the model
class.
my model class has some attributes that are lazy initialized and are
not mapped to any table columns.
i am using the getattr method to implement the lazy initialization.

Michael Bayer

unread,
Aug 3, 2009, 10:26:29 AM8/3/09
to sqlal...@googlegroups.com
rajasekhar911 wrote:
>
> the error can be reproduced by adding __getattr__ method to the model
> class.
> my model class has some attributes that are lazy initialized and are
> not mapped to any table columns.
> i am using the getattr method to implement the lazy initialization.

can you send a full example please including how you've implemented
`__getattr__`.
Reply all
Reply to author
Forward
0 new messages