-
Notifications
You must be signed in to change notification settings - Fork 13
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
feat: document / allow customization of dependencies with conflicting scopes #58
Comments
Some context on what Pytest does here: it always uses the fixture with the alphabetically largest string name. So basically undefined behavior. It certainly does not automatically use the |
In the end the decision was to not allow customization here and instead special case this as a prohibited usage |
I think this warrants re-opening in light of adriangb/xpresso#57 |
Some use cases for this: adriangb/xpresso#57In this case we want the dependencies to be treated as two separate unrelated entities. https://github.com/adriangb/xpresso/blob/main/docs_src/tutorial/lifespans/tutorial_001.pyIn this case we have a dependency ( class AppState(BaseModel):
started: bool = False
@asynccontextmanager
async def lifespan(state: AppState) -> AsyncIterator[None]: # implicit "app" scope
state.started = True
yield
async def healthcheck(state: Annotated[AppState, Dependant(scope="app")): # needs explicit "app" scope
return AppHealth(running=state.started) The problemWithin a DAG, I think we can either prohibit dependencies having the same scope (current behavior) or treat them as separate dependencies (previous behavior). The more problematic aspect is caching: should we look for the same dependency in another scope for caching? It seems like in the first case the answer is clearly "no" but in the second it is "yes". On the other hand, identifying a dependency only by its callable is a pretty sensible and understandable thing to do. |
What happens when the same dependency is declared with different scopes for a given DAG? Currently they are treated as different dependencies. But customizing
DependantBase.cache_key
they can be made to be treated as the same dependency. But this cannot be changed independently of caching. We could have 2"cache keys"
, but even then what if we want to have one replace the other, with some specific business logic?The text was updated successfully, but these errors were encountered: