Fix bare except clauses and mutable default arguments#8871
Merged
lstein merged 6 commits intoinvoke-ai:mainfrom Feb 23, 2026
Merged
Fix bare except clauses and mutable default arguments#8871lstein merged 6 commits intoinvoke-ai:mainfrom
lstein merged 6 commits intoinvoke-ai:mainfrom
Conversation
Replace bare `except:` with `except Exception:` in sqlite_database.py and mlsd/utils.py to avoid catching KeyboardInterrupt and SystemExit, which can prevent graceful shutdowns and mask critical errors (PEP 8 E722). Replace mutable default arguments (lists) with None in imwatermark/vendor.py to prevent shared state between calls, which is a known Python gotcha that can cause subtle bugs when default mutable objects are modified in place.
Collaborator
|
@Mr-Neutr0n Is there any way to add a test for this? |
Contributor
Author
|
added a test for this |
Collaborator
@Mr-Neutr0n Thanks. This PR is failing a python check. Once you address that, I'll be happy to review it. |
Collaborator
|
@Mr-Neutr0n There are a couple of ruff errors showing up in the tests. Could you fix? |
Removed unused database initialization in tests for KeyboardInterrupt and SystemExit.
Collaborator
|
@JPPhoto I went ahead and fixed the failing python check. I did a bit of testing on database rollback and didn't encounter any problems, but I didn't test the watermarking and MLSD control net functionality. |
Collaborator
|
@lstein I think this is good. It doesn't solve the double |
JPPhoto
approved these changes
Feb 21, 2026
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
except:withexcept Exception:insqlite_database.pyandmlsd/utils.pyto avoid inadvertently catchingKeyboardInterruptandSystemExit, which can prevent graceful shutdowns and mask critical errors (PEP 8 E722).[]) withNoneinimwatermark/vendor.py(set_by_bitsandEmbedMaxDct.__init__) to prevent shared state between calls — a well-known Python pitfall where default mutable objects persist across invocations and can cause subtle bugs if modified in place.Changes
invokeai/app/services/shared/sqlite/sqlite_database.pytransaction()context manager:except:→except Exception:invokeai/backend/image_util/mlsd/utils.pypred_squares(): three bareexcept:→except Exception:(lines 572, 578, 586)invokeai/backend/image_util/imwatermark/vendor.pyWatermarkEncoder.set_by_bits(bits=[])→set_by_bits(bits=None)withNoneguardEmbedMaxDct.__init__(watermarks=[], ..., scales=[0, 36, 36], ...)→__init__(watermarks=None, ..., scales=None, ...)withNoneguardsTest plan
invokeaiimports and starts without errors