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

Error thrown when trying to insert a row where the PK is not explicitly defined as autoincrement=False and does not have a column_identity value #71

Closed
reevery opened this issue Jan 2, 2018 · 3 comments
Labels
bug Unwanted / harmful behavior

Comments

@reevery
Copy link

reevery commented Jan 2, 2018

Hi

This has been bugging me for a while, but I only decided to look into this today.

I'm trying to insert a row into a table where the PK is a date. In my original schema, I had not defined autoincrement=False against this PK.

As a result, in get_lastrowid() in base.py, the first check autoincrement_pk_columns includes the PK column, so the return None is not executed at this stage. So, the function then goes on to find the column_identity column from exa_all_columns, which comes back Null.

As a result, the int(...) call is calling Null, and the exception is thrown.

The quick fix is to add a check of result[0] is None, and if so either throw a warning or error so that it's clear what the issue is, or ignore it and return None.

    session.commit()
  File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/orm/session.py", line 921, in commit
    self.transaction.commit()
  File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/orm/session.py", line 461, in commit
    self._prepare_impl()
  File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/orm/session.py", line 441, in _prepare_impl
    self.session.flush()
  File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/orm/session.py", line 2192, in flush
    self._flush(objects)
  File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/orm/session.py", line 2312, in _flush
    transaction.rollback(_capture_exception=True)
  File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/util/langhelpers.py", line 66, in __exit__
    compat.reraise(exc_type, exc_value, exc_tb)
  File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/util/compat.py", line 187, in reraise
    raise value
  File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/orm/session.py", line 2276, in _flush
    flush_context.execute()
  File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/orm/unitofwork.py", line 389, in execute
    rec.execute(self)
  File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/orm/unitofwork.py", line 548, in execute
    uow
  File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/orm/persistence.py", line 181, in save_obj
    mapper, table, insert)
  File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/orm/persistence.py", line 799, in _emit_insert_statements
    execute(statement, multiparams)
  File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/engine/base.py", line 945, in execute
    return meth(self, multiparams, params)
  File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/sql/elements.py", line 263, in _execute_on_connection
    return connection._execute_clauseelement(self, multiparams, params)
  File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/engine/base.py", line 1053, in _execute_clauseelement
    compiled_sql, distilled_params
  File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/engine/base.py", line 1202, in _execute_context
    result = context._setup_crud_result_proxy()
  File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/engine/default.py", line 896, in _setup_crud_result_proxy
    self._setup_ins_pk_from_lastrowid()
  File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/engine/default.py", line 932, in _setup_ins_pk_from_lastrowid
    lastrowid = self.get_lastrowid()
  File "/usr/local/lib/python3.4/dist-packages/sqlalchemy_exasol/base.py", line 327, in get_lastrowid
    return int(result[0]) - 1
TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'
@jank jank added the bug Unwanted / harmful behavior label Jan 9, 2018
@jank
Copy link

jank commented Jan 9, 2018

Thank you for digging out the details and root cause of your issue.
From what you write, throwing an exception sounds like a meaningful way to let the developer know what is going on (e.g. missing PK column).
Would you like to provide a pull request that fixes this issue for inclusion in next release?

@reevery
Copy link
Author

reevery commented Jan 14, 2018

I don't have it locally, so that's a lot of effort for potentially two lines of code, but if I ever fork it, then it will be top of my list.

@jank
Copy link

jank commented Jan 18, 2022

Closing this issue: not able to reproduce.

@jank jank closed this as completed Jan 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Unwanted / harmful behavior
Projects
None yet
Development

No branches or pull requests

2 participants