Fix empty name field error in metadata saving
All checks were successful
Deployment / deploy-docker (push) Successful in 15s
All checks were successful
Deployment / deploy-docker (push) Successful in 15s
This commit is contained in:
@@ -127,16 +127,21 @@ def fetch_metadata(isin):
|
||||
def save_metadata(metadata):
|
||||
# QuestDB Influx Line Protocol
|
||||
# table,tag1=val1 field1="str",field2=num timestamp
|
||||
name = metadata['name'].replace(' ', '\\ ').replace(',', '\\,')
|
||||
country = metadata['country']
|
||||
continent = metadata['continent']
|
||||
sector = metadata['sector']
|
||||
|
||||
# Ensure all fields have valid non-empty values
|
||||
name = metadata.get('name', 'Unknown') or 'Unknown'
|
||||
country = metadata.get('country', 'Unknown') or 'Unknown'
|
||||
continent = metadata.get('continent', 'Unknown') or 'Unknown'
|
||||
sector = metadata.get('sector', 'Unknown') or 'Unknown'
|
||||
isin = metadata['isin']
|
||||
|
||||
# Escape special characters in name for Influx Line Protocol
|
||||
name = name.replace(' ', '\\ ').replace(',', '\\,').replace('"', '\\"')
|
||||
|
||||
line = f'metadata,isin={isin} name="{name}",country="{country}",continent="{continent}",sector="{sector}"'
|
||||
|
||||
try:
|
||||
response = requests.post(f"http://{DB_HOST}:9000/write", data=line + "\n", auth=DB_AUTH)
|
||||
response = requests.post(f"http://{DB_HOST}:9000/write", data=line + "\\n", auth=DB_AUTH)
|
||||
if response.status_code not in [200, 204]:
|
||||
logger.error(f"Error saving metadata: {response.text}")
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user