Skip to content

Fix module shadowing in db_maintenance.py preventing script execution#54

Draft
Copilot wants to merge 2 commits intolstein/bugfix/gallery-maintenance-scriptfrom
copilot/fix-db-maintenance-error
Draft

Fix module shadowing in db_maintenance.py preventing script execution#54
Copilot wants to merge 2 commits intolstein/bugfix/gallery-maintenance-scriptfrom
copilot/fix-db-maintenance-error

Conversation

Copy link

Copilot AI commented Feb 1, 2026

Summary

Running python invokeai/backend/util/db_maintenance.py failed with ModuleNotFoundError: No module named 'logging.handlers'. The local logging.py shadowed stdlib's logging module when PIL was imported at module-level, causing PIL's internal import chain to resolve to the wrong module.

Changes:

  • Moved PIL imports from module-level to function-level in generate_thumbnail_for_image_name()
  • Removed unused PIL.ImageOps and PIL.PngImagePlugin imports (only PIL.Image is used)

This defers the import until after the script's namespace is established, avoiding the shadowing.

# Before (module-level)
import PIL
import PIL.ImageOps
import PIL.PngImagePlugin

# After (function-level)
def generate_thumbnail_for_image_name(self, image_filename):
    import PIL.Image
    # ... use PIL.Image

Related Issues / Discussions

Related to issue reporting ModuleNotFoundError when running db_maintenance script

QA Instructions

Run python invokeai/backend/util/db_maintenance.py --help - should display help without import errors.

Merge Plan

None required - isolated utility script fix.

Checklist

  • The PR has a short but descriptive title, suitable for a changelog
  • Tests added / updated (if applicable) - No existing tests for this utility
  • ❗Changes to a redux slice have a corresponding migration - N/A
  • Documentation added / updated (if applicable) - N/A
  • Updated What's New copy (if doing a release after this PR) - N/A
Original prompt

This section details on the original issue you should resolve

<issue_title>[bug]: Fix invokeai.utiil.db_maintenance</issue_title>
<issue_description>### Is there an existing issue for this problem?

  • I have searched the existing issues

Install method

Invoke's Launcher

Operating system

Linux

GPU vendor

Nvidia (CUDA)

GPU model

No response

GPU VRAM

16GB

Version number

6.11.0

Browser

No response

System Information

No response

What happened

I ran python invokeai/backend/util/db_maintenance and I got the error:

Traceback (most recent call last):
  File "/home/lstein/Projects/InvokeAI-lstein/invokeai/backend/util/db_maintenance.py", line 17, in <module>
    import PIL.ImageOps
  File "/home/lstein/invokeai-lstein/.venv/lib/python3.12/site-packages/PIL/ImageOps.py", line 27, in <module>
    from . import ExifTags, Image, ImagePalette
  File "/home/lstein/invokeai-lstein/.venv/lib/python3.12/site-packages/PIL/Image.py", line 33, in <module>
    import logging
  File "/home/lstein/Projects/InvokeAI-lstein/invokeai/backend/util/logging.py", line 177, in <module>
    import logging.handlers
ModuleNotFoundError: No module named 'logging.handlers'; 'logging' is not a package

What you expected to happen

I expected the maintenance script to run and identify and fix any mismatches between the database and the models on disk. Note that this script saiys it is for Invoke AI 3.0.0.0, so probably much has changed since then and the whole script should be reviewed for issues.

How to reproduce the problem

No response

Additional context

No response

Discord username

No response</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

…ction scope

Co-authored-by: lstein <111189+lstein@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix invokeai util db maintenance error Fix module shadowing in db_maintenance.py preventing script execution Feb 1, 2026
Copilot AI requested a review from lstein February 1, 2026 04:24
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