Skip to content

Handle CondFunc exception when resolving attributes#14560

Merged
AUTOMATIC1111 merged 1 commit intoAUTOMATIC1111:devfrom
Nuullll:condfunc-warning
Jan 7, 2024
Merged

Handle CondFunc exception when resolving attributes#14560
AUTOMATIC1111 merged 1 commit intoAUTOMATIC1111:devfrom
Nuullll:condfunc-warning

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 requested a review from AUTOMATIC1111 as a code owner January 6, 2024 10:18
@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
@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