GENI-NSF / geni-ch

GENI clearinghouse services
Other
3 stars 6 forks source link

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

Open tcmitchell opened 8 years ago

tcmitchell commented 8 years ago

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 commented 8 years ago

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.