feat(v3-vision): implement resilient "Heal-on-Read" ID resolution
1. Hardened Event_Exhibit and Event_Exhibit_Tracking models with automatic Redis/DB fallback for missing string IDs. 2. Fully modernized Event_Person_Tracking_Base to the Vision Standard (Union IDs + Root Validator). 3. Enabled account-based search for event_person_tracking. 4. Verified all changes via e2e demo parity suite.
This commit is contained in:
@@ -39,21 +39,45 @@ class Event_Exhibit_Base(BaseModel):
|
||||
"""
|
||||
Vision Transformer:
|
||||
Map DB keys to clean API keys and strip internal integers during READ operations.
|
||||
Falls back to Redis/DB lookups if random string IDs are missing from the view.
|
||||
"""
|
||||
# 1. Map Random Strings to Clean Names
|
||||
from app.db_sql import get_id_random
|
||||
|
||||
# 1. Map Primary Object ID
|
||||
rid = values.get('id_random') or values.get('event_exhibit_id_random')
|
||||
if rid and isinstance(rid, str):
|
||||
values['id'] = rid
|
||||
values['event_exhibit_id'] = rid
|
||||
|
||||
if a_rid := values.get('account_id_random'): values['account_id'] = a_rid
|
||||
if e_rid := values.get('event_id_random'): values['event_id'] = e_rid
|
||||
if o_rid := values.get('organization_id_random'): values['organization_id'] = o_rid
|
||||
if c_rid := values.get('contact_id_random'): values['contact_id'] = c_rid
|
||||
if p_rid := values.get('person_id_random'): values['person_id'] = p_rid
|
||||
if s_rid := values.get('status_id_random'): values['status_id'] = s_rid
|
||||
|
||||
# 2. Prevent leakage of integers during API responses (Vision Standard)
|
||||
elif values.get('id') and isinstance(values.get('id'), int):
|
||||
# Fallback for primary ID
|
||||
resolved_rid = get_id_random(values['id'], 'event_exhibit')
|
||||
if resolved_rid:
|
||||
values['id'] = resolved_rid
|
||||
values['event_exhibit_id'] = resolved_rid
|
||||
values['id_random'] = resolved_rid
|
||||
|
||||
# 2. Map & Resolve Relational IDs
|
||||
id_map = [
|
||||
('account_id', 'account'),
|
||||
('event_id', 'event'),
|
||||
('organization_id', 'organization'),
|
||||
('contact_id', 'contact'),
|
||||
('person_id', 'person'),
|
||||
('status_id', 'status'),
|
||||
]
|
||||
|
||||
for field, table in id_map:
|
||||
r_val = values.get(f'{field}_random')
|
||||
if r_val and isinstance(r_val, str):
|
||||
values[field] = r_val
|
||||
elif values.get(field) and isinstance(values[field], int):
|
||||
# Fallback: Resolve from Redis/DB if missing from view result
|
||||
resolved_rid = get_id_random(values[field], table)
|
||||
if resolved_rid:
|
||||
values[field] = resolved_rid
|
||||
values[f'{field}_random'] = resolved_rid
|
||||
|
||||
# 3. Final Vision Enforcement: Strip internal integers
|
||||
for k in ['id', 'event_exhibit_id', 'account_id', 'event_id', 'organization_id', 'contact_id', 'person_id', 'status_id']:
|
||||
val = values.get(k)
|
||||
if val is not None and not isinstance(val, str):
|
||||
|
||||
Reference in New Issue
Block a user