Fix bare except clauses and mutable default arguments #8871
+12
−6
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