computers: never file a part marker under its own PC
Some checks failed
CI / backend (push) Failing after 8s
CI / naming (push) Successful in 2s
CI / frontend (push) Successful in 8s
CI / migrations-mysql (push) Failing after 7s

A PC first seen before the machine-number fix was created with the machine
number as its OWN asset number, and the fix deliberately does not overwrite an
existing PC's asset number. So resolving the reported number can return the
reporting PC itself, and the marker was then filed partof its own PC - which
reads, on the machine page, as the PC being the operation.

The machine-link path already guarded this case; the marker path did not. It
now refuses and says why, naming the repair: rename the PC asset to its
hostname, or create the operation asset.
This commit is contained in:
cproudlock
2026-08-10 17:01:23 -04:00
parent a61739d1ab
commit 738f30dca3
2 changed files with 54 additions and 2 deletions

View File

@@ -1008,3 +1008,41 @@ def test_an_ordinary_pc_gets_no_marker(
'pctype': 'gea-shopfloor-collections'},
headers={'X-API-Key': collector_key})
assert Asset.query.filter(Asset.assetnumber.like('%-PARTMARKER')).all() == []
def test_a_marker_is_never_filed_under_its_own_pc(
client, db, collector_key, computer_assettype, machine_3015):
"""A PC first seen before the machine-number fix was created with the
machine number as its OWN asset number, and that is never overwritten. So
resolving the number can return the PC itself, and filing the marker partof
its own PC reads on the machine page as the PC being the operation."""
from shopdb.core.models import Asset, AssetRelationship, RelationshipType
from plugins.computers.models import Computer
db.session.add(RelationshipType(relationshiptype='partof',
isdirectional=True))
db.session.commit()
# A legacy PC: its own asset carries the machine number, and no separate
# asset for the operation exists.
client.post('/api/collector/computers',
json={'hostname': 'LEGACYPC',
'pctype': 'gea-shopfloor-partmarker'},
headers={'X-API-Key': collector_key})
comp = Computer.query.filter(Computer.hostname.ilike('LEGACYPC')).first()
comp.asset.assetnumber = '0615'
db.session.commit()
r = client.post('/api/collector/computers',
json={'hostname': 'LEGACYPC', 'machinenumber': '0615',
'pctype': 'gea-shopfloor-partmarker'},
headers={'X-API-Key': collector_key})
partof = RelationshipType.query.filter_by(relationshiptype='partof').first()
links = AssetRelationship.query.filter_by(
relationshiptypeid=partof.relationshiptypeid, isactive=True).all()
targets = [db.session.get(Asset, rel.targetassetid).assetid
for rel in links]
assert comp.assetid not in targets, 'marker filed under its own PC'
assert any("own asset number" in w
for w in r.get_json()['data']['warnings'])