-
Notifications
You must be signed in to change notification settings - Fork 1k
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
FastAPI route for tags (Disabled) #11224
Conversation
This sounds better than an empty 200. |
Update
I don't understand where is the difference between the two endpoint calls (legacy and FastAPI) since they both share the same class. Maybe there is some more magic happening in the legacy endpoint decorator that doesn't break the database session? |
This is a bigger issue, we need to always work with a SessionLocal database scope and we probably should separate this from the app object. Unfortunately I don't have a more concrete suggestion here, except that you could try tracking where those 2 different sessions come from. I need to fix something else urgently and then I will look into this (if noone beats me to it). |
The difference between the endpoints is probably the implementation of https://github.com/galaxyproject/galaxy/blob/dev/lib/galaxy/webapps/base/webapp.py#L170 I'm suspect based on Marius's comment this is not something we want to align between the endpoints though. So I'm not sure I have actionable advice without looking into it more. |
Can you modify that whole tag pipeline so |
Thank you both for the help! |
Actually I think I was a bit off: def get_trans(app: StructuredApp = depends(StructuredApp), user: Optional[User] = Depends(get_user),
galaxy_session: Optional[model.GalaxySession] = Depends(get_session),
) -> SessionRequestContext:
app.model.session.expunge_all()
return SessionRequestContext(app=app, user=user, galaxy_session=galaxy_session) It looks like in FastAPI the session is expunged after the user is loaded instead of before. Probably just moving that expunge_all line to the top of |
I have tried to move that line, but it keeps giving the |
These checks are done by the pydantic model now
78aef91
to
72a9936
Compare
The FastAPI router has been disabled until the database session issue is fixed. |
lib/galaxy/managers/tags.py
Outdated
item_class: str = Field( | ||
..., # This field is required | ||
title="Item class", | ||
description="The name of the class of the item.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make this an enum of all taggable item classes ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done! Great suggestion!
I've added to the enum the name of the classes that are listed in GalaxyTagHandler but I'm not sure if those are all of them or I may have missed some.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That looks complete to me. I've been thinking about maybe using a metaclass that will register new taggable classes (or https://stackoverflow.com/a/50099920), since they should all be subclass of ItemTagAssociation https://github.com/mvdbeek/galaxy/blob/5d1d29d838983748704cc89a246799e2224b2abc/lib/galaxy/model/__init__.py#L6348
But a simple enum here is fine for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the hint!
I changed the Enum and now it is dynamically generated based on the names of the subclasses of ItemTagAssociation
. This is a much better approach since we already found that there were some classes missing:
However, this brings some issues:
- Mypy can not correctly detect the Enum type and the only workaround to avoid the error that I found was ignoring it.
- The OpenAPI documentation does not show the enum values as it does with the regular Enums and the JSON that represents the model does not show the
item_class
property anymore. I'm not sure why :/
|
||
def __init_subclass__(cls, **kwargs): | ||
super().__init_subclass__(**kwargs) | ||
cls.associated_item_names.append(cls.__name__.replace("TagAssociation", "")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've not encountered this pattern before, very cool.
Ref #10889
Summary
TagManager
class shared with the new FastAPI controller.Additional comments
_schemas.py
file because I wasn't sure where would be a better place.204
status code so this is documented in the OpenAPI docs properly?Bad Request
). I've been staring at it for a couple of hours but it doesn't fix itself neither I managed to figure out the reason, maybe another pair of trained eyes can help 😄