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:
@@ -67,21 +67,24 @@ class Hosted_File_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. Capture the random ID string
|
||||
# 1. Map Random Strings to Clean Names
|
||||
rid = values.get('id_random') or values.get('hosted_file_id_random')
|
||||
|
||||
# 2. Map Random Strings to Clean Names for the Frontend
|
||||
# We always want the string version in 'id' and 'hosted_file_id' for the API response
|
||||
if rid:
|
||||
if rid and isinstance(rid, str):
|
||||
values['id'] = rid
|
||||
values['hosted_file_id'] = rid
|
||||
|
||||
if a_rid := values.get('account_id_random'):
|
||||
# If we have a random account ID string, use it for the Vision API
|
||||
values['account_id'] = a_rid
|
||||
if a_rid := values.get('account_id_random'): values['account_id'] = a_rid
|
||||
|
||||
# 2. Prevent "Collision Population" or leakage of integers during API responses
|
||||
for k in ['id', 'hosted_file_id', 'account_id']:
|
||||
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
|
||||
|
||||
class Config:
|
||||
|
||||
Reference in New Issue
Block a user