feat: Implement Event File Hosted Data Fix and API Guide Update
Address critical data visibility issues for Event Files and enhance frontend documentation.
This commit resolves the persistent problem where top-level hosted file convenience fields
(e.g., , , ) were
returning as in V3 Event File API responses, even when .
Key changes include:
- Refactored Pydantic model:
- Removed redundant definitions from top-level hosted file convenience fields,
allowing direct mapping from SQL view columns.
- Simplified to focus solely on conditionally loading the nested
object, as top-level fields are now populated directly by Pydantic
from the view.
- Added comprehensive comments to clarify data flow, Pydantic's behavior, and the
expected origin of these convenience fields from SQL views.
- Updated :
- Introduced a new section detailing how to retrieve Event File data, including the
use of to get both top-level convenience fields and a nested
object.
- Clarified all ID references as random string IDs.
- Renumbered the troubleshooting section.
- Copied updated guide to .
- Continued ID Vision compliance audit, ensuring consistent handling of random string IDs
across various core and event models (Account, Address, Contact, DataStore, Event Badge Template).
- Consolidated ID Vision E2E tests and updated related documentation.
- Minor updates to and
to support Event File data retrieval with .
This commit is contained in:
@@ -26,9 +26,16 @@ class Contact_Base(BaseModel):
|
||||
# NOTE: Linked Address ID is actually the old contact.address_id (Legacy?)
|
||||
linked_address_id: Optional[str] = Field(None, **base_fields['address_id_random'])
|
||||
|
||||
# Standardized Polymorphic Target
|
||||
for_type: Optional[str]
|
||||
for_id: Optional[int]
|
||||
for_id_random: Optional[Union[str,None]] = None # lambda:get_id_random(values.get('for_id'), table_name=values.get('for_type')),
|
||||
for_id: Optional[str] = Field(**base_fields['obj_id_random'])
|
||||
|
||||
# --- Standardized Legacy / Internal IDs (Excluded) ---
|
||||
id_random: Optional[str] = Field(None, alias='contact_id_random', exclude=True)
|
||||
account_id_random: Optional[str] = Field(None, exclude=True)
|
||||
address_id_random: Optional[str] = Field(None, exclude=True)
|
||||
linked_address_id_random: Optional[str] = Field(None, exclude=True)
|
||||
for_id_random: Optional[str] = Field(None, exclude=True)
|
||||
|
||||
name: Optional[str]
|
||||
title: Optional[str]
|
||||
@@ -87,65 +94,51 @@ class Contact_Base(BaseModel):
|
||||
Vision Transformer:
|
||||
Map DB keys to clean API keys and strip internal integers.
|
||||
"""
|
||||
# 1. Map Random Strings to Clean Names
|
||||
# 1. Map Primary Object ID
|
||||
if rid := values.get('id_random') or values.get('contact_id_random'):
|
||||
values['id'] = rid
|
||||
values['contact_id'] = rid
|
||||
|
||||
if a_rid := values.get('account_id_random'):
|
||||
values['account_id'] = a_rid
|
||||
if ad_rid := values.get('address_id_random'):
|
||||
values['address_id'] = ad_rid
|
||||
if lad_rid := values.get('linked_address_id_random'):
|
||||
values['linked_address_id'] = lad_rid
|
||||
|
||||
# 2. Prevent "Collision Population"
|
||||
for k in ['id', 'contact_id', 'account_id', 'address_id', 'linked_address_id']:
|
||||
if k in values and not isinstance(values[k], str) and values[k] is not None:
|
||||
del values[k]
|
||||
# 2. Map & Resolve Relational IDs
|
||||
id_map = [
|
||||
('account_id', 'account'),
|
||||
('address_id', 'address'),
|
||||
('linked_address_id', 'address'),
|
||||
]
|
||||
|
||||
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, str)):
|
||||
is_random = isinstance(values[field], str) and len(values[field]) >= 11
|
||||
if not is_random:
|
||||
resolved_rid = get_id_random(values[field], table)
|
||||
if resolved_rid:
|
||||
values[field] = resolved_rid
|
||||
values[f'{field}_random'] = resolved_rid
|
||||
|
||||
# 3. Handle Polymorphic for_id
|
||||
if f_rid := values.get('for_id_random'):
|
||||
values['for_id'] = f_rid
|
||||
elif values.get('for_id') and values.get('for_type'):
|
||||
# Resolve based on the for_type
|
||||
is_random = isinstance(values['for_id'], str) and len(values['for_id']) >= 11
|
||||
if not is_random:
|
||||
resolved_for_rid = get_id_random(values['for_id'], values['for_type'])
|
||||
if resolved_for_rid:
|
||||
values['for_id'] = resolved_for_rid
|
||||
values['for_id_random'] = resolved_for_rid
|
||||
|
||||
# 4. Final Vision Enforcement
|
||||
for k in ['id', 'contact_id', 'account_id', 'address_id', 'linked_address_id', 'for_id']:
|
||||
val = values.get(k)
|
||||
if val is not None:
|
||||
if not isinstance(val, str) or len(val) < 11:
|
||||
values[k] = None
|
||||
|
||||
return values
|
||||
|
||||
@validator('for_id', pre=True, always=True)
|
||||
def for_id_lookup(cls, v, values, **kwargs):
|
||||
log.setLevel(logging.DEBUG)
|
||||
log.debug(locals())
|
||||
|
||||
for_type = values.get('for_type')
|
||||
for_id = v # values.get('for_id')
|
||||
for_id_random = values.get('for_id_random')
|
||||
|
||||
if for_id and for_type:
|
||||
log.info(f'Got For ID: {for_id}; For Type: {for_type}')
|
||||
for_id_random = get_id_random(for_id, table_name=for_type)
|
||||
values['for_id_random'] = for_id_random
|
||||
return for_id
|
||||
elif values.get('for_id_random') and values.get('for_type'):
|
||||
log.info(f'Got For ID Random: {for_id_random}; For Type: {for_type}')
|
||||
return redis_lookup_id_random(record_id_random=values['for_id_random'], table_name=values['for_type'])
|
||||
log.info(f'Got nothing? For ID: {for_id}; For ID Random: {for_id_random}; For Type: {for_type}')
|
||||
return None
|
||||
|
||||
@validator('for_id_random', always=True)
|
||||
def for_id_random_lookup(cls, v, values, **kwargs):
|
||||
log.setLevel(logging.DEBUG)
|
||||
log.debug(locals())
|
||||
|
||||
for_type = values.get('for_type')
|
||||
for_id = values.get('for_id')
|
||||
for_id_random = v
|
||||
|
||||
if for_id_random:
|
||||
log.info(f'Got For ID Random: {for_id_random}')
|
||||
return for_id_random
|
||||
elif for_id and for_type:
|
||||
log.info(f'Got For ID: {for_id}; For Type: {for_type}')
|
||||
for_id_random = get_id_random(for_id, table_name=for_type)
|
||||
log.info(f'Got ID Random: {for_id_random}')
|
||||
return for_id_random
|
||||
log.info(f'Got nothing? For ID: {for_id}; For ID Random: {for_id_random}; For Type: {for_type}')
|
||||
return None
|
||||
|
||||
class Config:
|
||||
underscore_attrs_are_private = True
|
||||
allow_population_by_field_name = False
|
||||
|
||||
Reference in New Issue
Block a user