fix(v3-vision): platform-wide hardening of ID Vision models
Hardened root_validators in Journal, Post, Page, and Hosted File models to use Union[int, str] for Vision ID fields. This prevents resolved integer IDs from being deleted during CREATE/UPDATE operations, resolving a critical regression found during Post Comment bug fixing.
This commit is contained in:
@@ -14,19 +14,11 @@ class Page_Base(BaseModel):
|
||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
# --- Standardized Vision IDs (Strings) ---
|
||||
id: Optional[str] = Field(None, **base_fields['page_id_random'])
|
||||
page_id: Optional[str] = Field(None, **base_fields['page_id_random'])
|
||||
account_id: Optional[str] = Field(None, **base_fields['account_id_random'])
|
||||
site_id: Optional[str] = Field(None, **base_fields['site_id_random'])
|
||||
|
||||
# page_id_random: Optional[str] = Field(
|
||||
# **base_fields['page_id_random'],
|
||||
# alias = 'page_id_random',
|
||||
# )
|
||||
# id: Optional[int] = Field(
|
||||
# alias = 'page_id'
|
||||
# )
|
||||
# --- Standardized Vision IDs (Strings for API, Integers for DB) ---
|
||||
id: Optional[Union[int, str]] = Field(None, **base_fields['page_id_random'])
|
||||
page_id: Optional[Union[int, str]] = Field(None, **base_fields['page_id_random'])
|
||||
account_id: Optional[Union[int, str]] = Field(None, **base_fields['account_id_random'])
|
||||
site_id: Optional[Union[int, str]] = Field(None, **base_fields['site_id_random'])
|
||||
|
||||
code: Optional[str]
|
||||
name: Optional[str]
|
||||
@@ -69,22 +61,24 @@ class Page_Base(BaseModel):
|
||||
def map_v3_ids(cls, values):
|
||||
"""
|
||||
Vision Transformer:
|
||||
Map DB keys to clean API keys and strip internal integers.
|
||||
Map DB keys to clean API keys and strip internal integers during READ operations.
|
||||
During CREATE (POST) operations, we ensure resolved integers are preserved.
|
||||
"""
|
||||
# 1. Map Random Strings to Clean Names
|
||||
if rid := values.get('id_random') or values.get('page_id_random'):
|
||||
rid = values.get('id_random') or values.get('page_id_random')
|
||||
if rid and isinstance(rid, str):
|
||||
values['id'] = rid
|
||||
values['page_id'] = rid
|
||||
|
||||
if a_rid := values.get('account_id_random'):
|
||||
values['account_id'] = a_rid
|
||||
if s_rid := values.get('site_id_random'):
|
||||
values['site_id'] = s_rid
|
||||
if a_rid := values.get('account_id_random'): values['account_id'] = a_rid
|
||||
if s_rid := values.get('site_id_random'): values['site_id'] = s_rid
|
||||
|
||||
# 2. Prevent "Collision Population"
|
||||
# 2. Prevent "Collision Population" or leakage of integers during API responses
|
||||
for k in ['id', 'account_id', 'site_id']:
|
||||
if k in values and not isinstance(values[k], str):
|
||||
del values[k]
|
||||
val = values.get(k)
|
||||
if val is not None and not isinstance(val, str):
|
||||
if values.get(f'{k}_random') or (k=='id' and values.get('id_random')):
|
||||
del values[k]
|
||||
|
||||
return values
|
||||
|
||||
|
||||
Reference in New Issue
Block a user