Skip to content

Commit process of UPDATE clause fails #179

Closed
@hyagi96

Description

@hyagi96

If you try to commit an UPDATE (and DELETE) clause for an existing row, you will get an error.
This issue(#121) may be relevant.
A minimal example is shown below.

Environment details

  • Programming language: Python
  • OS: Ubuntu 20.04, macOS 12.0.1
  • Language runtime version: 3.9.9
  • Package version:

Steps to reproduce

  1. clone above repository and run init.sh, create virtualenv using pipenv.
  2. $ pipenv shell to enter virtualenv.
  3. $ cp .env.example .env and $ vi .env to add environment variables such as project ID, spanner instance ID, database ID, and credential json file path.
    You need to create a Spanner instance beforehand and then create a database using Google standard SQL.
  4. $ ./run.py .
    The first time you run it, it will only perform INSERT, so no error will occur.
  5. $ ./run.py again.
    An error occurs in session.commit to existing row (because rowcount is not implemented).

cf. Error log when running run.py for the second time in my environment

/[current_dir]/.venv/lib/python3.9/site-packages/sqlalchemy/engine/default.py:1237: UserWarning: The `rowcount` property is non-operational. Request resulting rows are streamed by the `fetch*()` methods and can't be counted before they are all streamed.
  return self.cursor.rowcount
Traceback (most recent call last):
  File "/[current_dir]/./run.py", line 55, in <module>
    session.commit()
  File "/[current_dir]/.venv/lib/python3.9/site-packages/sqlalchemy/orm/session.py", line 1046, in commit
    self.transaction.commit()
  File "/[current_dir]/.venv/lib/python3.9/site-packages/sqlalchemy/orm/session.py", line 504, in commit
    self._prepare_impl()
  File "/[current_dir]/.venv/lib/python3.9/site-packages/sqlalchemy/orm/session.py", line 483, in _prepare_impl
    self.session.flush()
  File "/[current_dir]/.venv/lib/python3.9/site-packages/sqlalchemy/orm/session.py", line 2540, in flush
    self._flush(objects)
  File "/[current_dir]/.venv/lib/python3.9/site-packages/sqlalchemy/orm/session.py", line 2682, in _flush
    transaction.rollback(_capture_exception=True)
  File "/[current_dir]/.venv/lib/python3.9/site-packages/sqlalchemy/util/langhelpers.py", line 68, in __exit__
    compat.raise_(
  File "/[current_dir]/.venv/lib/python3.9/site-packages/sqlalchemy/util/compat.py", line 182, in raise_
    raise exception
  File "/[current_dir]/.venv/lib/python3.9/site-packages/sqlalchemy/orm/session.py", line 2642, in _flush
    flush_context.execute()
  File "/[current_dir]/.venv/lib/python3.9/site-packages/sqlalchemy/orm/unitofwork.py", line 422, in execute
    rec.execute(self)
  File "/[current_dir]/.venv/lib/python3.9/site-packages/sqlalchemy/orm/unitofwork.py", line 586, in execute
    persistence.save_obj(
  File "/[current_dir]/.venv/lib/python3.9/site-packages/sqlalchemy/orm/persistence.py", line 230, in save_obj
    _emit_update_statements(
  File "/[current_dir]/.venv/lib/python3.9/site-packages/sqlalchemy/orm/persistence.py", line 998, in _emit_update_statements
    rows += c.rowcount
TypeError: unsupported operand type(s) for +=: 'int' and 'NoneType'

Metadata

Metadata

Assignees

Labels

api: spannerIssues related to the googleapis/python-spanner-sqlalchemy API.priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions