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
UserInfo can't have a ForeignKey with JupyterHub User model #26
Comments
@minrk heya! Do you think you'll have any time to help me / @leportella out on this one? We're trying to use the same db that JupyterHub is using for the authenticator too... |
The tables User and UserInfo are in the same schema (in database)? Using the Base = declarative_base() the objects should share the same variable Base... Can you import and use the same variable Base of jupyterhub/jupyterhub/orm.py? |
@dedeco I just tested it on a simple example I was working and it seems to work fine! I'll test using |
@dedeco , @yuvipanda it worked! |
Sorry, didn't catch up before it looks like it was solved. Great! I think I would probably advise strongly against custom authenticators using the private jupyterhub.orm and creating anything in the jupyterhub databases directly, though. There's absolutely no guarantee that anything there is stable for public consumption (not the tables, not the classes, not the orm module existing at all). |
@minrk I'll open another issue to discuss this, since this is closed :) |
So, I created a class called
UserInfo
to store extra information on the user that the default JupyterHubUser
class won't. TheUserInfo
class can be seen here.This table (
user_info
) is created on the Authenticator__init__
method by the following way:UserInfo.__table__.create(self.db)
whereself.db
is a SQLAlchemy Engine instance.However, when I try to add a relationship between
UserInfo
andUser
, this method won't work. Usually I get this error:NoReferencedTableError: Foreign key associated with column 'product.user_id' could not find table 'user' with which to generate a foreign key to target column 'id'
I created a simple example and the main problem that I found is that, if I create both tables at the same time (using
Base.metadata.create_all(engine)
) everything works fine. The problem is creating the relationship after theUser
table has already been created.Since I am not changing anything on JupyterHub, the
User
table is always created before the moment I create theUserInfo
table, so I can't change this for now.Some things I tried on the process:
User
class before the creation of the new table by using this command:User.__mapper__.add_property('products', relationship("product", collection_class=set))
automap_base
instead of adeclarative_base
, then created theUserInfo
table before by usingself.db.execute(..SQL..)
and then get the table usingautomap
.For now, my
UserInfo
is not related to User, and it only uses the same username in the momento of creation since I have no idea how to fix this.The text was updated successfully, but these errors were encountered: