79769608

Date: 2025-09-19 14:12:43
Score: 0.5
Natty:
Report link

When you use an f string you are converting everything to strings. Since str(None) == 'None' you will simply end up the string 'None'. There are more ways two handle this. (The best would in my opinion be some sort of orm like sqlalchemy to properly handle the data types). However if you just want a quick fix in python:

insert_qry = f"""
        INSERT INTO cust_db.purchases(customer_id, customer_name, purchase_date, city, customer_nickname, customer_address_type)
        VALUES ({purchase_input["customer_id"]}, 
        '{purchase_input["customer_name"]}', 
        '{purchase_input["purchase_date"]}', 
        '{purchase_input["city"]}',
        {f"'{purchase_input["customer_nickname"]}'" if purchase_input["customer_nickname"] else "NULL"},
        {f"'{purchase_input["customer_address_type"]}'" if purchase_input["customer_address_type"] else "NULL"},
        )"""

NOTE: In no means is this clean python code but it would work.

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Starts with a question (0.5): When you use an
  • Low reputation (1):
Posted by: sjors blom