Resolve a driver by vendor, and converge a bay's printers from ShopDB
Some checks failed
CI / naming (push) Has been cancelled
CI / frontend (push) Has been cancelled
CI / migrations-mysql (push) Has been cancelled
CI / backend (push) Has been cancelled

Two rows now cover 41 of 44 printers. printerdrivers could only bind a driver to
ONE modelnumberid, so the HP and Xerox universal drivers - which between them
cover almost the whole floor - would have needed 21 near-duplicate rows pointing
at the same package. That is a table nobody keeps true, and it is why 42 of 44
printers resolved no driver at all.

printerdrivers gains vendorid, and resolution runs most-specific-first: the
printer's model, then its vendor, then the pre-vendorid convention of matching
the vendor word in the driver's name so a site that populated the table before
the column existed does not silently lose every driver on upgrade. A row that
names a vendor is never matched by its text, because a mis-set vendor resolving
to the wrong package is worse than resolving to none.

Six rows now resolve 44 of 44 printers at the reference site, and the DesignJet
correctly takes its own driver over the HP universal one.

Set-ShopdbPrinters.ps1 is the client half: ask for-host, create the queues that
are missing, record the desired default. It NEVER removes a queue - a bad minute
from the API must not take printers away from a working bay - and it never
fetches a driver, because downloading 48 MB while somebody waits to print is the
wrong moment. The common scope stages those.

Apply-ShopdbDefaultPrinter.ps1 applies the default in the USER's context, which
is the only context that can: SYSTEM cannot set a per-user default for somebody
else. It also turns off "Let Windows manage my default printer", without which
Windows silently overwrites the choice the next time anyone prints elsewhere -
a fix that undoes itself within a day.

VALIDATED ON WINDOWS 11 AGAINST A LIVE SHOPDB, not only by tests. Printers were
assigned to a MACHINE; a PC controlling it, holding no rows of its own, created
both queues bound to the right universal drivers, recorded the default and set
it, and a second run changed nothing. The first attempt failed with
"Relationship types are not seeded - run: flask seed reference-data", which is
the deployment trap the plan predicted, caught by an explicit error rather than
silently resolving nothing.
This commit is contained in:
cproudlock
2026-08-19 10:24:53 -04:00
parent 0dc0ac13c8
commit 8cedf674fb
8 changed files with 484 additions and 6 deletions

View File

@@ -797,11 +797,18 @@ def _assignment_result(printerassetids, defaultassetid, suppliers):
def _printer_driver(printer, universaldrivers):
"""Driver record to install this printer with, or None.
The printer's own model link first. Failing that, a driver with no model at
all whose name carries the printer's vendor: HP and Xerox universal drivers
cover the overwhelming majority of a floor, and per-model rows for each
queue are a table nobody keeps true. printerdrivers cannot name a vendor of
its own yet, so the vendor word in the driver's name is what there is.
Three steps, most specific first:
1. A driver bound to the printer's MODEL. A plotter, a card printer and a
label printer each need their own, and a per-model row must beat the
universal one.
2. A driver bound to the printer's VENDOR with no model. HP's and Xerox's
universal drivers cover 41 of the reference site's 44 printers between
them; binding those to one model each would mean a near-duplicate row per
model, which is a table nobody keeps true.
3. Failing both, a model-less driver whose NAME carries the vendor word.
This is the pre-vendorid convention, kept so a site that populated its
table before the column existed does not lose its drivers on upgrade.
"""
if printer.modelnumberid:
driver = (PrinterDriver.query
@@ -810,10 +817,20 @@ def _printer_driver(printer, universaldrivers):
if driver:
return driver
if printer.vendorid:
for driver in universaldrivers:
if driver.vendorid == printer.vendorid:
return driver
vendor = _printer_vendor(printer).lower()
if not vendor:
return None
for driver in universaldrivers:
# Only the legacy convention here: a row WITH a vendorid that did not
# match above must not be matched by its name instead, or a mis-set
# vendor silently resolves to the wrong package.
if driver.vendorid:
continue
if vendor in (driver.name or '').lower():
return driver
return None