Name the missing relationship types in the seed error

The printer assignment routes checked usesprinter and defaultprinter
together and reported one generic string: "Relationship types are not
seeded". A partially seeded table is the common case, so that message
sends someone looking for an empty table they will not find.

Found on this stack: relationshiptypes held 9 rows including
defaultprinter and controls, but usesprinter had never been inserted -
the id sequence shows it was never created rather than created and
deleted, since defaultprinter took the id usesprinter would have used.
The missing type also silently cost defaultprinter its propagation rail,
because _seed_propagation returns without comment when either end is
absent, so one gap broke assignment in two places.

Now reports which types are actually missing, e.g. "Relationship type(s)
not seeded: usesprinter - run: flask seed reference-data". Same check,
same 500, same remedy; it just says what is wrong.

Present on main, wj and dev-be as well.
This commit is contained in:
benjamin.baker
2026-09-06 18:39:12 -04:00
parent 7d3ddba61e
commit 811e6ca61a

View File

@@ -1123,12 +1123,18 @@ def set_asset_printer_assignment(asset_id: int):
', '.join(str(assetid) for assetid in sorted(notprinters))))
typeids = _relationship_typeids(_USES_PRINTER, _DEFAULT_PRINTER)
if not typeids[_USES_PRINTER] or not typeids[_DEFAULT_PRINTER]:
missingtypes = [name for name in (_USES_PRINTER, _DEFAULT_PRINTER)
if not typeids[name]]
if missingtypes:
# Seed data, not a migration. An un-seeded database cannot hold an
# assignment, and saying so beats writing rows nothing can read.
# assignment, and saying so beats writing rows nothing can read. Name
# the types that are actually missing: a partially seeded table is the
# common case, and "types are not seeded" sends someone looking for an
# empty table they will not find.
return error_response(
ErrorCodes.INTERNAL_ERROR,
'Relationship types are not seeded - run: flask seed reference-data',
'Relationship type(s) not seeded: {0} - run: flask seed '
'reference-data'.format(', '.join(missingtypes)),
http_code=500)
_reconcile_edges(asset_id, typeids[_USES_PRINTER][0],
@@ -1784,10 +1790,13 @@ def seed_assignment_from_observed(asset_id: int):
details={'hostname': hostname, 'skipped': candidate['skipped']})
typeids = _relationship_typeids(_USES_PRINTER, _DEFAULT_PRINTER, _CONTROLS)
if not typeids[_USES_PRINTER] or not typeids[_DEFAULT_PRINTER]:
missingtypes = [name for name in (_USES_PRINTER, _DEFAULT_PRINTER)
if not typeids[name]]
if missingtypes:
return error_response(
ErrorCodes.INTERNAL_ERROR,
'Relationship types are not seeded - run: flask seed reference-data',
'Relationship type(s) not seeded: {0} - run: flask seed '
'reference-data'.format(', '.join(missingtypes)),
http_code=500)
warnings = []