-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
refactor(nodes): invocation registration logic #7826
base: main
Are you sure you want to change the base?
refactor(nodes): invocation registration logic #7826
Conversation
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.
Nice change! The code is clearer with these 2 classes separated.
I've left some suggestions for improvement.
@@ -340,6 +249,105 @@ def invoke_internal(self, context: InvocationContext, services: "InvocationServi | |||
TBaseInvocation = TypeVar("TBaseInvocation", bound=BaseInvocation) | |||
|
|||
|
|||
class InvocationRegistry: |
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.
@psychedelicious
I’d recommend using regular instance methods instead of classmethods.
This allows clients to create and manage their own instances, or you can use the singleton pattern if a global instance is needed.
Same convenience, but more flexible and easier to test.
@classmethod | ||
@lru_cache(maxsize=1) | ||
def get_invocation_typeadapter(cls) -> TypeAdapter[Any]: | ||
"""Gets a pydantic TypeAdapter for the union of all invocation types. |
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.
If the invocation allowlist or denylist is changed, the cache should be cleared
If the allowlist/denylist are passed in as arguments, then the lru_cache
will handle this clearing automatically, reducing the burden on clients and avoiding bugs if they forget.
Thanks! There's no urgency to this PR - I just remembered I've had this branch in my local clone for a couple weeks and figured I should push it. I'll review the suggestions when I have spare time. |
Summary
InvocationRegistry
class to handle invocation registration. Previously it was all inBaseInvocation
andBaseInvocationOutput
. This was a bit awkward as logic for execution was mixed up with registration. The actual logic is the same, but the responsibilities are split up in a more logical way.@lru_cache(maxsize=1)
instead of what effectively was a bespoke version of the same logic.Related Issues / Discussions
n/a
QA Instructions
App should still work. Custom nodes should still work. Works for me. No issues expected as its pretty straightforward.
Merge Plan
n/a
Checklist
What's New
copy (if doing a release after this PR)