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
SqlAlchemy InvalidColumnReference error when listing entities that have a lazy="subquery" relationship #210
Comments
I've made a pull request if ever I was right : #211 |
Well it looks like it's not as simple as a one line fix because of the type expected (str) : Also assigning a column directly to an admin model propery raises an
Could be easier to run the nested select statement without the order by somehow ? |
@lebrunthibault Can you please update the sample code with the SQLAdmin code so that I can reproduce the issue? Maybe you're talking about two issues at the same time that I could not follow. And for this:
You can do: class UserAdmin(ModelAdmin, model=UserOrm):
name = 'Utilisateur'
column_default_sort = [(UserOrm.email, False)] # Or (UserOrm.email, False) TBH I think in |
of course. here you go : # publications.py
from kessel.models.images import ImageOrm
class PublicationOrm(Base):
__tablename__ = "publications"
id = Column(String, primary_key=True)
...
profile_picture_id = Column(String, ForeignKey("images.id"))
_cropped_profile_picture = relationship(
"ImageOrm", lazy="subquery", foreign_keys=[profile_picture_id])
# images.py
class ImageOrm(Base):
__tablename__ = "images"
id = Column(String, primary_key=True)
_filename = Column("filename", String)
x = Column(Integer)
y = Column(Integer)
width = Column(Integer)
height = Column(Integer)
# admin/publication.py
from sqladmin import ModelAdmin
from kessel.models.publications import PublicationOrm
class PublicationAdmin(ModelAdmin, model=PublicationOrm):
name = 'Publication' And then go to : /publication-orm/list NB : if I remove
Oh I see the point for Flask-Admin. I agree with you |
I can't seem to reproduce this, what database and driver are you using? |
Did you try with data ? INSERT
INTO images(id, filename)
VALUES (1, 'c6918f95-8711-4934-965a-71c7d998ac6c.jpeg');
INSERT INTO publications (id, profile_picture_id) VALUES (1, 1) I'm using stock |
@lebrunthibault It would be great if you could also test it with your project, and also you could update the title as it's not really about default sort column, but another issue with lazy subquery. |
I'm sorry I don't have much time today but it doesn't seem to fix the problem for me. Having my model with Thanks anyway, I'll be able to test again on monday |
@lebrunthibault It does seem to solve the problem for me, can you please provide the what the issue is with this implementation? |
My bad I might have tested the wrong branch it actually works :) |
Checklist
master
.Describe the bug
When going on /list the SELECT SQLAlchemy statement fails with the following error :
We have an InvalidColumnReference
SELECT DISTINCT, ORDER BY expressions must appear in select list
I'm having this error only on a specific model which has a One to One on another table (lazy="subquery")
It seems to be order_by should use the column and not the column name
Steps to reproduce the bug
I'm having Two models, roughtly
I expect someone having this setup and getting the /list page to have a 500 error (see above)
Expected behavior
No error
Actual behavior
500 error
Debugging material
No response
Environment
Additional context
No response
The text was updated successfully, but these errors were encountered: