Skip to content

Conversation

@Mr-Neutr0n
Copy link

Summary

  • Replace bare except: with except Exception: in sqlite_database.py and mlsd/utils.py to avoid inadvertently catching KeyboardInterrupt and SystemExit, which can prevent graceful shutdowns and mask critical errors (PEP 8 E722).
  • Replace mutable default arguments ([]) with None in imwatermark/vendor.py (set_by_bits and EmbedMaxDct.__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.py

  • transaction() context manager: except:except Exception:

invokeai/backend/image_util/mlsd/utils.py

  • pred_squares(): three bare except:except Exception: (lines 572, 578, 586)

invokeai/backend/image_util/imwatermark/vendor.py

  • WatermarkEncoder.set_by_bits(bits=[])set_by_bits(bits=None) with None guard
  • EmbedMaxDct.__init__(watermarks=[], ..., scales=[0, 36, 36], ...)__init__(watermarks=None, ..., scales=None, ...) with None guards

Test plan

  • Verify invokeai imports and starts without errors
  • Verify MLSD control net processor works correctly
  • Verify watermark encoding/decoding still functions as expected
  • Verify database transactions commit and rollback correctly

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.
@github-actions github-actions bot added python PRs that change python files backend PRs that change backend files services PRs that change app services labels Feb 11, 2026
@JPPhoto
Copy link
Collaborator

JPPhoto commented Feb 12, 2026

@Mr-Neutr0n Is there any way to add a test for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend PRs that change backend files python PRs that change python files services PRs that change app services

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants