Fix empty name field error in metadata saving
All checks were successful
Deployment / deploy-docker (push) Successful in 15s

This commit is contained in:
Melchior Reimers
2026-01-25 15:07:17 +01:00
parent 445eb0b482
commit 9161300cfc

View File

@@ -127,16 +127,21 @@ def fetch_metadata(isin):
def save_metadata(metadata): def save_metadata(metadata):
# QuestDB Influx Line Protocol # QuestDB Influx Line Protocol
# table,tag1=val1 field1="str",field2=num timestamp # table,tag1=val1 field1="str",field2=num timestamp
name = metadata['name'].replace(' ', '\\ ').replace(',', '\\,')
country = metadata['country'] # Ensure all fields have valid non-empty values
continent = metadata['continent'] name = metadata.get('name', 'Unknown') or 'Unknown'
sector = metadata['sector'] country = metadata.get('country', 'Unknown') or 'Unknown'
continent = metadata.get('continent', 'Unknown') or 'Unknown'
sector = metadata.get('sector', 'Unknown') or 'Unknown'
isin = metadata['isin'] 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}"' line = f'metadata,isin={isin} name="{name}",country="{country}",continent="{continent}",sector="{sector}"'
try: 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]: if response.status_code not in [200, 204]:
logger.error(f"Error saving metadata: {response.text}") logger.error(f"Error saving metadata: {response.text}")
except Exception as e: except Exception as e: