Skip to content
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[release-jobs]: Circular Dependency in ValidateJobAction #1668

Open
sbliven opened this issue Jan 28, 2025 · 2 comments
Open

bug[release-jobs]: Circular Dependency in ValidateJobAction #1668

sbliven opened this issue Jan 28, 2025 · 2 comments
Assignees

Comments

@sbliven
Copy link
Member

sbliven commented Jan 28, 2025

Summary

I'm currently struggling with a circular dependency in the validateaction. This issue is half plea for help and half documenting my attempts. I expect the issue to generalize to other JobActions in the future.

Steps to Reproduce

The issue relates to my validateaction-circular branch. Here's the dependency graph, where errors indicate an imports relation between NestJS modules:

Loading
flowchart LR

DatasetsModule --> CaslModule
CaslModule --> JobConfigModule
JobConfigModule --> CoreJobActionCreators
CoreJobActionCreators --> ValidateJobActionModule
ValidateJobActionModule -->|forwardRef| DatasetsModule

CaslService needs to get authorization info from the JobConfigModule. ValidateJobActionModule needs to access the database to retrieve dataset information.

NestJS provides a doc page on circular dependencies which suggests breaking the circle using a forwardRef. This somewhat works in the above branch (the app starts up), but numerous tests fail due to remaining circular dependencies. Adding forwardRef to every import of CaslModule fixes the circular dependency errors, but gives further errors about the database connections not being set up.

Another suggestion from the docs is to use ModuleRef to load the module dynamically. I tried this in the validateaction branch. Tests pass, but the app doesn't start because the DatasetService is not available at runtime in the correct context.

@sbliven sbliven self-assigned this Jan 28, 2025
@sbliven
Copy link
Member Author

sbliven commented Jan 28, 2025

@fpotier @despadam Thanks for your suggestions on this.

@sbliven
Copy link
Member Author

sbliven commented Feb 3, 2025

This is now fixed in #1473. ModuleRef was the correct path, with the DatasetService getting resolved at runtime rather than during dependency injection since DatasetService has REQUEST scope.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant