FirebirdSQL / python3-driver

Firebird driver for Python that uses new Firebird API
https://www.firebirdsql.org/en/devel-python-driver/
MIT License
27 stars 10 forks source link

'datetime.date' object has no attribute 'date' #38

Closed kevnoli closed 5 months ago

kevnoli commented 5 months ago

I'm building an API with FastAPI that connects to a Firebird 3.0.4 database.

For an endpoint that accepts a model with a date field and tries to update a table with that date, I'm getting the following error message:

File "[...]/site-packages/firebird/driver/core.py", line 179, in _encode_timestamp
    return _util.encode_date(v.date()).to_bytes(4, 'little') + _util.encode_time(datetime.time()).to_bytes(4, 'little')
AttributeError: 'datetime.date' object has no attribute 'date'

I believe that this code could be fixed by removing the call to date()

if isinstance(v, datetime.date):
    return _util.encode_date(v).to_bytes(4, 'little') + _util.encode_time(datetime.time()).to_bytes(4, 'little')
raise ValueError("datetime.datetime or datetime.date expected")
pcisar commented 5 months ago

Fixed. Thanks for your report.