Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default value for column doesn`t work #455

Closed
Mikkgn opened this issue Dec 6, 2019 · 0 comments · Fixed by #456
Closed

Default value for column doesn`t work #455

Mikkgn opened this issue Dec 6, 2019 · 0 comments · Fixed by #456

Comments

@Mikkgn
Copy link
Contributor

Mikkgn commented Dec 6, 2019

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
Mikkgn pushed a commit to Mikkgn/aiomysql that referenced this issue Dec 11, 2019
Mikkgn pushed a commit to Mikkgn/aiomysql that referenced this issue Dec 11, 2019
Mikkgn pushed a commit to Mikkgn/aiomysql that referenced this issue Apr 28, 2020
Mikkgn pushed a commit to Mikkgn/aiomysql that referenced this issue Apr 28, 2020
terrycain pushed a commit that referenced this issue May 6, 2020
Co-authored-by: mikkegn <mganjin@ussc.ru>
andr-04 added a commit to andr-04/aiomysql that referenced this issue May 18, 2021
* commit '0a8af2355562ea961477738d66b3334332447186':
  Bump version and tweak setup.py (aio-libs#540)
  Fill changelog for 0.0.21 release (aio-libs#538)
  Support python 3.7 and 3.8 in tests and travis CI
  Update dependencies (aio-libs#485)
  chore(flake8): fixed flake8 errors (aio-libs#484)
  added support for sqlalchemy default parameters aio-libs#455 (aio-libs#456)
  Fix flake
  Fixed invalid datatime for MySQL 5.7
  Rewrote tests to use pytest exclusively
  Fixed linting
  Attempted to move db completely to docker
  Fix Travis attempt 1
  Fix aio-libs#454
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant