Hi,
I should say in advance that I don't have a reproduction script for this,
though I could probably manufacture one if necessary.
I have a python script which calls a function repeatedly. Each time the
function is called, it creates a bunch of SQLA tables, classes and mappers
between them. I'd be perfectly happy to remove these after each
invocation, but I don't know how, and apparently they stick around. I'd
hope that these objects all get overwritten. Since the classes are just
regular Python classes, I know these do get overwritten. I'm not sure
about the Table objects, and it definitely appears that the mappers don't
get cleanly overwritten, judging by the error message I get (complete
traceback at the bottom of the message)
sqlalchemy.exc.ArgumentError: Class '<class 'dbschema.Pheno'>' already has
a primary mapper defined. Use non_primary=True to create a non primary
Mapper. clear_mappers() will remove *all* current mappers from all
classes.
So, I want to
a) confirm that the Table objects get overwritten (they contain state
data, correct?) and I don't want the Table objects from a previous
invocation to get mixed up with one from a later invocation.
and ask
b) why aren't the mappers overwritten?
I'm using clear_mappers as a temporary measure. as suggested by the error
message, but I don't know if this the right approach. It does get rid of
the error message. Clarifications appreciated. I apologise if this message
comes across as "computationally illiterate" but despite using SQLA for
nearly two years (has it been so long?), I still have little understanding
of how some of it's magic is accomplished. Thanks!
Regards, Faheem
***********************************************************************
traceback follows
***********************************************************************
Traceback (most recent call last):
File "load_all_datasets.py", line 58, in <module>
load_all_datasets(dbname, dbtype, options.test, options.shard,
options.recreate, options.jobs)
File "/home/faheem/snppy/utils.py", line 6, in wrapper
res = func(*args, **kwargs)
File "load_all_datasets.py", line 39, in load_all_datasets
load_dataset(schema, dbname, options.alleletype, options.jobs,
options.recreate, options.shard, options.test)
File "/home/faheem/snppy/load_dataset.py", line 71, in load_dataset
p = platform.Single_Illumina(phenofiles, annotfile, genofile,
genotablefile, newschema, alleletype, dbtype, dbstring_dbname, jobs)
File "/home/faheem/snppy/platform.py", line 130, in __init__
table_dict = make_tables_illumina(schema)
File "/home/faheem/snppy/dbschema.py", line 293, in make_tables
'race':relation(Race, backref='patients'),
File "/usr/lib/pymodules/python2.5/sqlalchemy/orm/__init__.py", line
751, in mapper
return Mapper(class_, local_table, *args, **params)
File "/usr/lib/pymodules/python2.5/sqlalchemy/orm/mapper.py", line 197,
in __init__
self._configure_class_instrumentation()
File "/usr/lib/pymodules/python2.5/sqlalchemy/orm/mapper.py", line 349,
in _configure_class_instrumentation
self.class_)
sqlalchemy.exc.ArgumentError: Class '<class 'dbschema.Pheno'>' already has
a primary mapper defined. Use non_primary=True to create a non primary
Mapper. clear_mappers() will remove *all* current mappers from all
classes.
--
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.