mirror of
https://github.com/maziggy/bambuddy.git
synced 2026-05-09 05:35:30 +02:00
[GH-ISSUE #689] [Bug]: can't link more than one smart switch to a printer #455
Labels
No labels
A1
automated
automated
bug
bug
Closed due to inactivity
contrib
dependencies
dependencies
duplicate
enhancement
feedback
hold
invalid
Notes
P1S
pull-request
security
security
ThumbsUp
user-report
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/bambuddy#455
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @ManuelW77 on GitHub (Mar 13, 2026).
Original GitHub issue: https://github.com/maziggy/bambuddy/issues/689
Originally assigned to: @maziggy on GitHub.
Bug Description
Found a bug at settings smart switches.
I want to link a second smart switch to a printer, for a heater.
But if i try to link the second switch i get a error 500.
I found that the database has a constraint that only one printer_id can be set.
[bambuddy] 2026-03-13T09:22:17.856100165Z sqlalchemy.exc.IntegrityError: (sqlite3.IntegrityError) UNIQUE constraint failed: smart_plugs.printer_id
[bambuddy] 2026-03-13T09:22:17.856132153Z [SQL: UPDATE smart_plugs SET printer_id=?, updated_at=CURRENT_TIMESTAMP WHERE smart_plugs.id = ?]
Expected Behavior
error 500
Steps to Reproduce
create a second switch an try to link to a printer which has already a switch.
get error 500
Printer Model
P1S
Bambuddy Version
v0.2.2b3
Printer Firmware Version
01.08.0000
Installation Method
Docker
Operating System
Linux (Ubuntu/Debian)
Relevant Logs / Support Package
Screenshots
No response
Additional Context
No response
Checklist
@maziggy commented on GitHub (Mar 13, 2026):
Cannot reproduce the issue. Please upload a support package.
@ManuelW77 commented on GitHub (Mar 13, 2026):
Yes, you added a first switch. now add a second switch to the same printer.
https://github.com/maziggy/bambuddy/issues/691#issue-4070739522
@maziggy commented on GitHub (Mar 13, 2026):
My primary switch is a Tasmota switch added to Bambuddy. Secondary switch is the HA switch entity.
@ManuelW77 commented on GitHub (Mar 13, 2026):
i try to add two ha switches to a single printer.
@ManuelW77 commented on GitHub (Mar 13, 2026):
the debug log says it, there are only one printer_id allowed at this table.
@maziggy commented on GitHub (Mar 13, 2026):
Ahhhh...got it.
@maziggy commented on GitHub (Mar 13, 2026):
The migration that removes the UNIQUE constraint on printer_id was silently skipping your database because it used an exact string match to detect the constraint, and your database (created with an older version) has the constraint expressed differently in the SQLite schema.
This is fixed in dev branch and available in the next release — the migration now uses pattern matching that handles all the ways SQLite can express a UNIQUE constraint (inline, table-level, quoted column names, standalone indexes).
Workaround until the update: You can fix your database manually by running:
docker exec -it bambuddy sqlite3 /app/data/bambuddy.db
Then paste:
-- Check current schema
SELECT sql FROM sqlite_master WHERE type='table' AND name='smart_plugs';
-- If it shows UNIQUE on printer_id, the migration didn't run.
-- The next update will fix this automatically.
Multiple HA switches per printer is already supported — this was just the migration not detecting the old constraint in your database.
@maziggy commented on GitHub (Mar 13, 2026):
Does it work now for you?
@ManuelW77 commented on GitHub (Mar 13, 2026):
I'm waiting for the next b4 package :)
@ManuelW77 commented on GitHub (Mar 13, 2026):
I've tested the daily beta and now it works :)