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
bug: injected dependency is not available in filter functions. #2310
Comments
Hello @hsblhsn, could you create a simple example using https://github.com/ent/bug? |
Hi @hsblhsn , which filters function do you mean? c.User.Query().Where(user.NameEQ("yoni")).OnlyX(ctx) Where are you expecting to get access to the Dependency? |
Suppose I have And I have a api client to check if the user has access to the pet. so in a privacy filter function, I would use it like. pets := m.APIClient.GetAllPets(ctx)
filter.Where(user.HasPetsIn(pets)) I have injected The problem is I can't access Thank you! |
Why not add your API Client to the context (where you add the pet name)? |
Nice idea! Thanks for that. But still, it would be nice for a dependency to be accessible from FilterFuncs. Because that's the whole point of creating a dependency at entity level. |
I think the reason is to avoid security issues by allowing the privacy layer to access the data it's protecting. |
No real reason, the ent/entc/integration/privacy/rule/rule.go Lines 111 to 121 in 4cf6dd7
@hsblhsn, I wonder how you use the Do you use generic |
Hello, dependency injection is a good feature and I have followed this tutorial to implement mine.
Current Behavior 😯
Currently, my dependencies are available inside the hook functions and in every mutation like
ent.UserMutation
. But I can't access them inside the filter function or type. They are not available inent.UserFilter
.Expected Behavior 🤔
I expect the injected dependencies to be available all over my ent packages wherever I can touch.
Your Environment 🌎
The text was updated successfully, but these errors were encountered: