Closed
Description
I've found, that default column value doesnt work in aiomysql. For example, here is a table definition:
from datetime import datetime
import sqlalchemy as sa
metadata = sa.MetaData()
data_source_table = sa.Table(
'data_source',
metadata,
sa.Column('id', UUID, nullable=False, primary_key=True, default=uuid.uuid4),
sa.Column('source_box_id', UUID, nullable=False, index=True),
sa.Column('updated_at', sa.dialects.mysql.DATETIME(fsp=6), nullable=False, default=datetime.utcnow),
)
And executing following code:
await db_conn.execute(
data_source_table.insert().values(source_box_id=box_id)
)
we get actual behavior with this error:
File "/test/run.py", line 216, in execute
data_source_table.insert().values(source_box_id=box_id)
File "/usr/local/lib/python3.7/site-packages/aiomysql/sa/connection.py", line 173, in _execute
await cursor.execute(str(compiled), post_processed_params)
File "/usr/local/lib/python3.7/site-packages/aiomysql/cursors.py", line 239, in execute
await self._query(query)
File "/usr/local/lib/python3.7/site-packages/aiomysql/cursors.py", line 457, in _query
await conn.query(q)
File "/usr/local/lib/python3.7/site-packages/aiomysql/connection.py", line 428, in query
await self._read_query_result(unbuffered=unbuffered)
File "/usr/local/lib/python3.7/site-packages/aiomysql/connection.py", line 622, in _read_query_result
await result.read()
File "/usr/local/lib/python3.7/site-packages/aiomysql/connection.py", line 1105, in read
first_packet = await self.connection._read_packet()
File "/usr/local/lib/python3.7/site-packages/aiomysql/connection.py", line 593, in _read_packet
packet.check_error()
File "/usr/local/lib/python3.7/site-packages/pymysql/protocol.py", line 220, in check_error
err.raise_mysql_exception(self._data)
File "/usr/local/lib/python3.7/site-packages/pymysql/err.py", line 109, in raise_mysql_exception
raise errorclass(errno, errval)
pymysql.err.IntegrityError: (1048, "Column 'id' cannot be null")
Expected behavior:
aiomysql should insert default values from the column.default property
Package versions:
- sqlalchemy==1.3.11
- pymysql==0.9.2
- aiomysql==0.0.20
Metadata
Metadata
Assignees
Labels
No labels