python - SQLAlchemy InvalidRequestError: failed to locate name happens only on gunicorn -


okay, have following. in user/models.py:

class user(usermixin, surrogatepk, model):     __tablename__ = 'users'     id = column(db.integer, primary_key=true, index=true)     username = column(db.string(80), unique=true, nullable=false)     email = column(db.string(80), unique=false, nullable=false)     password = column(db.string(128), nullable=true)     departments = relationship("department",secondary="user_department_relationship_table", back_populates="users") 

and in department/models.py:

user_department_relationship_table=db.table('user_department_relationship_table',                              db.column('department_id', db.integer,db.foreignkey('departments.id'), nullable=false),                              db.column('user_id',db.integer,db.foreignkey('users.id'),nullable=false),                              db.primarykeyconstraint('department_id', 'user_id') )   class department(surrogatepk, model):     __tablename__ = 'departments'     id = column(db.integer, primary_key=true, index=true)     name = column(db.string(80), unique=true, nullable=false)     short_name = column(db.string(80), unique=true, nullable=false)     users = relationship("user", secondary=user_department_relationship_table,back_populates="departments") 

using flask development server locally works totally fine. however, once deploy standard python buildpack on heroku, cpt/app.py loads both modules register blueprints:

from cpt import (         public, user, department         )  ...   def register_blueprints(app):     app.register_blueprint(public.views.blueprint)     app.register_blueprint(user.views.blueprint)     app.register_blueprint(department.views.blueprint)     return none 

and errors out following:

sqlalchemy.exc.invalidrequesterror: when initializing mapper mapper|user|users, expression 'user_department_relationship_table' failed locate name ("name 'user_department_relationship_table' not defined"). if class name, consider adding relationship() class after both dependent classes have been defined.

i'd know if there's better way organize these parts avoid error obviously, i'm more curious why organization works fine on development server blows fierce on gunicorn/heroku.

well can't explain discrepancy between heroku , dev server, got error go away changing department mode from

users = relationship("department",secondary="user_department_relationship_table", back_populates="users") 

to

users = relationship("user", secondary=user_department_relationship_table, backref="departments") 

which sets user model automatically in turn means can delete mention of department , relationship table on end.

¯\_(ツ)_/¯


Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -