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

Handle CondFunc exception when resolving attributes #14560

Merged
merged 1 commit into from
Jan 7, 2024

Conversation

Nuullll
Copy link
Contributor

@Nuullll Nuullll commented Jan 6, 2024

Description

  • Handle potential AttributeError on getattr. This happens when orig_func string refers to a non-existent object.

For example, I attempted to hijack sd-webui-controlnet annotator.anime_face_segment.AnimeFaceSegment.__init__ in my extension. However, annotator.anime_face_segment is only available starting from ControlNet >= 1.1.420.

Screenshots/videos:

# Example usage
CondFunc('annotator.anime_face_segment.AnimeFaceSegment.__init__', ..., ...)
foo()

Before this change, an uncaught exception may be thrown at CondFunc instantiation, and foo() will not be executed unless we wrap every CondFunc with a try-except block, which is inconvenient.

      File "D:\stable-diffusion-webui\modules\sd_hijack_utils.py", line 15, in __new__
        resolved_obj = getattr(resolved_obj, attr_name)
    AttributeError: module 'annotator' has no attribute 'anime_face_segment'

After this change, a warning will be printed indicating this CondFunc didn't take effect:

Warning: Failed to resolve annotator.anime_face_segment.AnimeFaceSegment.__init__ for CondFunc hijack

image

Checklist:

@Nuullll Nuullll marked this pull request as draft January 6, 2024 10:22
@Nuullll Nuullll marked this pull request as ready for review January 6, 2024 10:27
@AUTOMATIC1111 AUTOMATIC1111 merged commit 30aa5e0 into AUTOMATIC1111:dev Jan 7, 2024
3 checks passed
@w-e-w w-e-w mentioned this pull request Feb 17, 2024
@pawel665j pawel665j mentioned this pull request Apr 16, 2024
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

Successfully merging this pull request may close these issues.

2 participants