Bug fixes related to file uploads. Fixing id_random int vs str confusion. For account and for hosted_file.
This commit is contained in:
@@ -171,24 +171,37 @@ def lookup_id_random_pop(
|
||||
]
|
||||
|
||||
for prefix in id_prefixes:
|
||||
key = f'{prefix}_id_random'
|
||||
if key in obj_data:
|
||||
# Table name mapping
|
||||
table = prefix
|
||||
if prefix == 'address_location': table = 'address'
|
||||
elif prefix in ['contact_1', 'contact_2']: table = 'contact'
|
||||
elif prefix == 'event_id_random_only': table = 'event'
|
||||
elif prefix == 'poc_event_person': table = 'event_person'
|
||||
elif prefix == 'poc_person': table = 'person'
|
||||
key_random = f'{prefix}_id_random'
|
||||
key_id = f'{prefix}_id'
|
||||
|
||||
# Table name mapping
|
||||
table = prefix
|
||||
if prefix == 'address_location': table = 'address'
|
||||
elif prefix in ['contact_1', 'contact_2']: table = 'contact'
|
||||
elif prefix == 'event_id_random_only': table = 'event'
|
||||
elif prefix == 'poc_event_person': table = 'event_person'
|
||||
elif prefix == 'poc_person': table = 'person'
|
||||
|
||||
resolved_id = None
|
||||
|
||||
# Scenario A: Legacy suffix (e.g., account_id_random: "abc")
|
||||
if key_random in obj_data:
|
||||
resolved_id = redis_lookup_id_random(record_id_random=obj_data[key_random], table_name=table)
|
||||
obj_data.pop(key_random)
|
||||
|
||||
resolved_id = redis_lookup_id_random(record_id_random=obj_data[key], table_name=table)
|
||||
obj_data[f'{prefix if not prefix.endswith("_id_random_only") else prefix[:-15]+"_id_only"}'] = resolved_id
|
||||
# Special case for event_id_random_only
|
||||
target_id_key = f'{prefix[:-7]}' if prefix.endswith('_random') else f'{prefix}_id'
|
||||
# Scenario B: Vision naming (e.g., account_id: "abc")
|
||||
# Only resolve if it's a string of the correct length (random ID format)
|
||||
elif key_id in obj_data and isinstance(obj_data[key_id], str) and 11 <= len(obj_data[key_id]) <= 22:
|
||||
resolved_id = redis_lookup_id_random(record_id_random=obj_data[key_id], table_name=table)
|
||||
|
||||
if resolved_id is not None:
|
||||
# Set the target ID field
|
||||
target_id_key = key_id
|
||||
if prefix == 'event_id_random_only': target_id_key = 'event_id_only'
|
||||
|
||||
obj_data[target_id_key] = resolved_id
|
||||
obj_data.pop(key)
|
||||
|
||||
# Also set the short prefix version (e.g., obj_data['account'] = 1) for compatibility
|
||||
obj_data[f'{prefix if not prefix.endswith("_id_random_only") else prefix[:-15]+"_id_only"}'] = resolved_id
|
||||
|
||||
# Polymorphic links
|
||||
polymorphic = [
|
||||
@@ -200,12 +213,19 @@ def lookup_id_random_pop(
|
||||
]
|
||||
|
||||
for type_key, rand_key, id_key in polymorphic:
|
||||
# Handle random key if present
|
||||
if type_key in obj_data and rand_key in obj_data:
|
||||
obj_data[id_key] = redis_lookup_id_random(
|
||||
record_id_random=obj_data.get(rand_key),
|
||||
table_name=obj_data.get(type_key)
|
||||
)
|
||||
obj_data.pop(rand_key)
|
||||
# Handle Vision naming (id_key contains the string)
|
||||
elif type_key in obj_data and id_key in obj_data and isinstance(obj_data[id_key], str) and 11 <= len(obj_data[id_key]) <= 22:
|
||||
obj_data[id_key] = redis_lookup_id_random(
|
||||
record_id_random=obj_data.get(id_key),
|
||||
table_name=obj_data.get(type_key)
|
||||
)
|
||||
|
||||
return obj_data
|
||||
|
||||
|
||||
Reference in New Issue
Block a user