Ah, sorry I think I solved my own problem. I was doing something silly
where I was creating Student instances before mapping class. Following
advice, I put the code creating Student instances after calling
mapper(Student, students_table) and it worked out.

Many thanks for trying to replicate the scenario and I apologise for
that!

Az


On Apr 9, 4:16 pm, "Michael Bayer" <mike...@zzzcomputing.com> wrote:
> Az wrote:
> > instance_dict(instance))
> > AttributeError: 'NoneType' object has no attribute 'get'
> > +++
>
> > I'm at a loss as to how to resolve this issue, if it is an issue. If
> > more information is required, please ask and I will provide it.
>
> you'd have to illustrate a full test example which replicates this
> behavior.  I have re-built a test case from your fragments and cannot
> reproduce:
>
> from sqlalchemy import *
> from sqlalchemy.orm import *
> import collections
>
> class Student(object):
>     def __init__(self, name, id):
>         self.id = id
>         self.name = name
>         self.preferences = collections.defaultdict(set)
>         self.own_proj_id = None
>         self.own_proj_sup = None
>         self.allocated_project = None
>         self.allocated_rank = 0
>
>     def __repr__(self):
>         return str(self)
>
>     def __str__(self):
>         return "%s %s" %(self.id, self.name)
>
> engine = create_engine('sqlite:///:memory:', echo=False)
> metadata = MetaData()
> students_table = Table('studs', metadata,
>     Column('id', Integer, primary_key=True),
>     Column('name', String)
> )
> metadata.create_all(engine)
> mapper(Student, students_table)
>
> Session = sessionmaker(bind=engine)
> sesh = Session()
>
> students = {}
> for id in xrange(10):
>     students[id] = Student("student %d" % id, id)
>
> for student in students.itervalues():
>     print student
>
> metadata.create_all(engine)
>
> sesh.add_all(students.values())
> sesh.flush()
>
> for student in students.itervalues():
>     print student
>
> sesh.commit()
>
> for student in students.itervalues():
>     print student
>
> zzzeek-3:sqlalchemy classic$ python test.py
> 0 student 0
> 1 student 1
> 2 student 2
> 3 student 3
> 4 student 4
> 5 student 5
> 6 student 6
> 7 student 7
> 8 student 8
> 9 student 9
> 0 student 0
> 1 student 1
> 2 student 2
> 3 student 3
> 4 student 4
> 5 student 5
> 6 student 6
> 7 student 7
> 8 student 8
> 9 student 9
> 0 student 0
> 1 student 1
> 2 student 2
> 3 student 3
> 4 student 4
> 5 student 5
> 6 student 6
> 7 student 7
> 8 student 8
> 9 student 9
>
>
>
> > Kind regards,
>
> > Az
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "sqlalchemy" group.
> > To post to this group, send email to sqlalch...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > sqlalchemy+unsubscr...@googlegroups.com.
> > For more options, visit this group at
> >http://groups.google.com/group/sqlalchemy?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to