On 06/23/2016 03:30 PM, Chung wrote:
We're occasionally seeing this exception thrown out of
mapper.configure_mappers when using SQLSoup in our webapp:

|

File"/home/glados/.virtualenvs/pod-glance/local/lib/python2.7/site-packages/sqlsoup.py",line
455,in__getattr__
    returnself.entity(attr)

File"/home/glados/.virtualenvs/pod-glance/local/lib/python2.7/site-packages/sqlsoup.py",line
452,inentity
    returnself.map_to(attr,tablename=attr,schema=schema)

File"/home/glados/.virtualenvs/pod-glance/local/lib/python2.7/site-packages/sqlsoup.py",line
363,inmap_to
    mapper_args

File"/home/glados/.virtualenvs/pod-glance/local/lib/python2.7/site-packages/sqlsoup.py",line
172,in_class_for_table
    fork inmappr.iterate_properties:

File"/home/glados/.virtualenvs/pod-glance/local/lib/python2.7/site-packages/sqlalchemy/orm/mapper.py",line
1819,initerate_properties
    configure_mappers()

File"/home/glados/.virtualenvs/pod-glance/local/lib/python2.7/site-packages/sqlalchemy/orm/mapper.py",line
2677,inconfigure_mappers
    formapper inlist(_mapper_registry):
  File"/usr/lib/python2.7/weakref.py",line 327,initerkeys
    forwr inself.data.iterkeys():
RuntimeError:dictionary changed size during iteration
|

I saw a previous thread about this
<https://groups.google.com/forum/#!searchin/sqlalchemy/%22RuntimeError$3A$20dictionary$20changed$20size$20during$20iteration%22/sqlalchemy/Qcwzn_GqUdQ/7n28bZqfPKYJ>
 and
indeed we are creating new SQLSoup instances per request not per
process.  But I also note that since then, it seems that sqlalchemy does
use a _CONFIGURE_MUTEX to avoid unsynchronized reference to
_mapper_registry.

Any idea what might be causing this?

adding new mappers while the configure() step is running would cause this, so if you are building mapped classes in requests, this would happen.

It's incredibly inefficient to create a SQLSoup mapped class on a per-request basis, because you're not only mapping, you're also reflecting the table structure from the database, so unless you have potentially millions of tables I'd look to set up all the mappers you need up front. The automap extension (which supersedes SQLSoup) makes this pretty simple.






Thanks,
Chung

--
You received this message because you are subscribed to the Google
Groups "sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to sqlalchemy+unsubscr...@googlegroups.com
<mailto:sqlalchemy+unsubscr...@googlegroups.com>.
To post to this group, send email to sqlalchemy@googlegroups.com
<mailto:sqlalchemy@googlegroups.com>.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to