Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Class '<class 'tools.mapped_tables.MemberAttribute'>' already has a primary mapper defined. #503

Open
tcmitchell opened this issue May 10, 2016 · 1 comment

Comments

@tcmitchell
Copy link
Member

We have sporadically seen a SQLAlchemy error about a specific class that already has a primary mapper defined:

mod_wsgi (pid=13674): Exception occurred processing WSGI script '/usr/share/geni-ch/chapi/chapi/tools/ch_server.wsgi'.
Traceback (most recent call last):
  File "/usr/share/geni-ch/chapi/chapi/tools/ch_server.py", line 65, in application
    initialize()
  File "/usr/share/geni-ch/chapi/chapi/tools/ch_server.py", line 57, in initialize
    plugins.marm.plugin.setup()
  File "/usr/share/geni-ch/chapi/chapi/plugins/marm/plugin.py", line 33, in setup
    delegate = MAv1Implementation()
  File "/usr/share/geni-ch/chapi/chapi/plugins/marm/MAv1Implementation.py", line 141, in __init__
    mapper(MemberAttribute, self.db.MEMBER_ATTRIBUTE_TABLE)
  File "<string>", line 2, in mapper
  File "/usr/local/lib/python2.7/dist-packages/SQLAlchemy-1.0.0b4-py2.7-linux-i686.egg/sqlalchemy/orm/mapper.py", line 625, in __init__
    self._configure_class_instrumentation()
  File "/usr/local/lib/python2.7/dist-packages/SQLAlchemy-1.0.0b4-py2.7-linux-i686.egg/sqlalchemy/orm/mapper.py", line 1122, in _configure_class_instrumentation
    self.class_)
ArgumentError: Class '<class 'tools.mapped_tables.MemberAttribute'>' 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.

This has occurred on one of our development hosts with some frequency recently. It also occurred a few times about a week ago on our staging host.

On the development host I rearranged the lines in MAv1Implementation.__init__() so that the MemberAttribute class was mapped last instead of first. The error when away. When I put the code back the way it was, the error did not reoccur. This means it is not reproducible. It has not occurred since.

@tcmitchell
Copy link
Member Author

A theory we have is that maybe the initialize() function in ch_server.py is being called a second time before the first occurrence has finished initializing. The chapi.log file for the same time period as the error above (which was in Apache's error log) shows that it never reached the last line of initialize() where "INITIALIZED CH_SERVER" is logged. If this is the case, perhaps we could add a semaphore to initialize to indicate that the system is initializing so that other threads do not re-enter the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant