Browse Source

Archive skip log names the auto-archive switch that caused it (#3477)

- Since 1.3.0 the global "Auto-archive prints" switch takes effect for
  prints started outside Bambuddy; before it was saved and never read
- An install upgraded with it off stopped archiving, and the log only
  said "auto_archive: False", the same as for a printer's own switch
- The skip line now names the global switch or the printer
maziggy 9 hours ago
parent
commit
1e33def354
2 changed files with 32 additions and 9 deletions
  1. 17 5
      backend/app/main.py
  2. 15 4
      backend/tests/integration/test_global_auto_archive_switch.py

+ 17 - 5
backend/app/main.py

@@ -5206,9 +5206,8 @@ async def on_print_start(printer_id: int, data: dict):
         from backend.app.api.routes.settings import get_setting
         from backend.app.api.routes.settings import get_setting
 
 
         _global_auto_archive = await get_setting(db, "auto_archive")
         _global_auto_archive = await get_setting(db, "auto_archive")
-        archives_prints = printer.auto_archive and (
-            _global_auto_archive is None or _global_auto_archive.lower() == "true"
-        )
+        _global_archives = _global_auto_archive is None or _global_auto_archive.lower() == "true"
+        archives_prints = printer.auto_archive and _global_archives
         if not archives_prints:
         if not archives_prints:
             # auto-archive disabled — check if there's an expected print (dispatched
             # auto-archive disabled — check if there's an expected print (dispatched
             # by BamBuddy via queue/reprint) that already has an archive to promote.
             # by BamBuddy via queue/reprint) that already has an archive to promote.
@@ -5235,8 +5234,21 @@ async def on_print_start(printer_id: int, data: dict):
             _has_expected = any(k in _expected_prints for k in _check_keys)
             _has_expected = any(k in _expected_prints for k in _check_keys)
 
 
             if not _has_expected:
             if not _has_expected:
-                # No expected print — truly external print (started from slicer/touchscreen)
-                logger.info("[CALLBACK] Skipping archive - auto_archive: False, no expected print")
+                # No expected print — truly external print (started from slicer/touchscreen).
+                # Say which switch it was: before 1.3.0 the global one was saved
+                # and never read, so an install upgraded with it off stopped
+                # archiving with nothing to point at it (#3477).
+                if not _global_archives:
+                    logger.info(
+                        "[CALLBACK] Skipping archive: the global 'Auto-archive prints' switch "
+                        "(Settings > General > Archive Settings) is off, and Bambuddy did not start this print"
+                    )
+                else:
+                    logger.info(
+                        "[CALLBACK] Skipping archive: auto-archive is off for printer %s, "
+                        "and Bambuddy did not start this print",
+                        printer_id,
+                    )
                 if not notification_sent:
                 if not notification_sent:
                     _no_archive_creator: int | None = None
                     _no_archive_creator: int | None = None
                     for _key in _check_keys:
                     for _key in _check_keys:

+ 15 - 4
backend/tests/integration/test_global_auto_archive_switch.py

@@ -5,6 +5,8 @@ printer's own switch decides. The global switch used to be saved and never
 read, so turning it off changed nothing.
 read, so turning it off changed nothing.
 """
 """
 
 
+import logging
+
 import pytest
 import pytest
 from sqlalchemy import select
 from sqlalchemy import select
 
 
@@ -24,14 +26,19 @@ async def _archives(db_session) -> list:
 
 
 @pytest.mark.asyncio
 @pytest.mark.asyncio
 @pytest.mark.integration
 @pytest.mark.integration
-async def test_global_off_archives_nothing(test_engine, db_session, printer_factory):
+async def test_global_off_archives_nothing(test_engine, db_session, printer_factory, caplog):
     printer = await printer_factory()
     printer = await printer_factory()
     db_session.add(Settings(key="auto_archive", value="false"))
     db_session.add(Settings(key="auto_archive", value="false"))
     await db_session.commit()
     await db_session.commit()
 
 
-    await _drive_print_start(test_engine, printer, download_ok=False)
+    with caplog.at_level(logging.INFO, logger="backend.app.main"):
+        await _drive_print_start(test_engine, printer, download_ok=False)
 
 
     assert await _archives(db_session) == []
     assert await _archives(db_session) == []
+    # The log names the switch: upgraded installs had it off without knowing,
+    # as it did nothing before 1.3.0 (#3477).
+    assert "global 'Auto-archive prints' switch" in caplog.text
+    assert "auto-archive is off for printer" not in caplog.text
 
 
 
 
 @pytest.mark.asyncio
 @pytest.mark.asyncio
@@ -48,12 +55,16 @@ async def test_global_on_lets_the_printer_decide(test_engine, db_session, printe
 
 
 @pytest.mark.asyncio
 @pytest.mark.asyncio
 @pytest.mark.integration
 @pytest.mark.integration
-async def test_a_printer_switched_off_stays_off_under_global_on(test_engine, db_session, printer_factory):
+async def test_a_printer_switched_off_stays_off_under_global_on(test_engine, db_session, printer_factory, caplog):
     printer = await printer_factory(auto_archive=False)
     printer = await printer_factory(auto_archive=False)
+    printer_id = printer.id
 
 
-    await _drive_print_start(test_engine, printer, download_ok=False)
+    with caplog.at_level(logging.INFO, logger="backend.app.main"):
+        await _drive_print_start(test_engine, printer, download_ok=False)
 
 
     assert await _archives(db_session) == []
     assert await _archives(db_session) == []
+    assert f"auto-archive is off for printer {printer_id}" in caplog.text
+    assert "global 'Auto-archive prints' switch" not in caplog.text
 
 
 
 
 @pytest.mark.asyncio
 @pytest.mark.asyncio