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 4 days ago
parent
commit
f0d6a138da
3 changed files with 33 additions and 9 deletions
  1. 1 0
      CHANGELOG.md
  2. 17 5
      backend/app/main.py
  3. 15 4
      backend/tests/integration/test_global_auto_archive_switch.py

+ 1 - 0
CHANGELOG.md

@@ -9,6 +9,7 @@ All notable changes to Bambuddy will be documented in this file.
 ### Changed
 
 ### Fixed
+- **The log says which auto-archive switch skipped a print (#3477, reported by @Fuzzylog2x)** — Since 1.3.0 the global **Auto-archive prints** switch (Settings > General > Archive Settings) takes effect for prints started outside Bambuddy. Before, it was saved and never read, so an install upgraded with it off stopped archiving, and the statistics stopped updating. The log only said "auto_archive: False", the same as for a printer's own switch. It now names the global switch or the printer, whichever turned archiving off.
 - **A camera window no longer opens a dozen streams to the printer at once (#3431, reported by @buffdriver)** — When the floating camera window was open while the page loaded (after a refresh, for example), Bambuddy opened about twenty camera streams for it. Only one was shown. The browser kept the rest open until the tab was closed, and they filled its six connections to the server. The page started each stream while still preparing to draw the window. It prepared the window several times before showing it, and every attempt left a stream behind. Streams now start only once the window is on the page. The camera page, the camera wall and the stream overlay start their streams the same way.
 - **A printer whose file service hangs during a print is no longer asked again and again until it refuses every upload (#3474, reported by @F9mm)** — When the card could not be read at print start, the timelapse baseline was read again every two minutes for the whole print, and each round walked the card twice: up to eight new FTPS connections, each hanging for 30 s against a hung printer. An H2S kept a session for every one of them, then answered every connection with "421 There are too many connections", and no queued job could reach it until the printer was restarted. The card is now read once per round. It is read again only while the print records a timelapse, the wait doubles after each failed round (up to 30 minutes), and it stops after five. A connection or listing that times out now pauses the background timelapse scans of that printer for five minutes. Opening files and sending prints are not held up by this. A printer that answers "421 too many connections" now gets its own message in the queue, saying it may need a restart, instead of "Bambuddy will retry automatically". Wiki updated.
 

+ 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
 
         _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:
             # auto-archive disabled — check if there's an expected print (dispatched
             # 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)
 
             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:
                     _no_archive_creator: int | None = None
                     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.
 """
 
+import logging
+
 import pytest
 from sqlalchemy import select
 
@@ -24,14 +26,19 @@ async def _archives(db_session) -> list:
 
 @pytest.mark.asyncio
 @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()
     db_session.add(Settings(key="auto_archive", value="false"))
     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) == []
+    # 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
@@ -48,12 +55,16 @@ async def test_global_on_lets_the_printer_decide(test_engine, db_session, printe
 
 @pytest.mark.asyncio
 @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_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 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