Skip to content

mysql.dml.Insert.values shadows the generative function sql.expression.Insert.values #4072

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

Closed
sqlalchemy-bot opened this issue Sep 9, 2017 · 6 comments
Labels
bug Something isn't working low priority mysql

Comments

@sqlalchemy-bot
Copy link
Collaborator

Migrated issue, originally created by Jack Zhou (@univerio)

When using the ON DUPLICATE KEY UPDATE support for MySQL, the .values() generative function is not available, contrary to the claims made by the documentation.

Traceback (most recent call last):
  File "/usr/lib/python3.5/runpy.py", line 184, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.5/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "kronos/__main__.py", line 97, in <module>
    cli()
  File "/home/ashu/Documents/kronos/venv/lib/python3.5/site-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/home/ashu/Documents/kronos/venv/lib/python3.5/site-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "kronos/__main__.py", line 31, in invoke
    return super(CLI, self).invoke(ctx)
  File "/home/ashu/Documents/kronos/venv/lib/python3.5/site-packages/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/ashu/Documents/kronos/venv/lib/python3.5/site-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/ashu/Documents/kronos/venv/lib/python3.5/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/home/ashu/Documents/kronos/scripts/gilmore_from_scratch.py", line 46, in gilmore_from_scratch
    stmt = insert(GilmoreItem.__table__).values(**to_insert)
TypeError: 'ImmutableColumnCollection' object is not callable

It appears to be shadowed by the .values property intended to support the VALUES(...) construct. Perhaps the column collection could be named values_ instead?

The workaround is to specify values with the insert constructor:

stmt = insert(GilmoreItem.__table__, values=to_insert)
@sqlalchemy-bot
Copy link
Collaborator Author

Michael Bayer (@zzzeek) wrote:

doh. clearly it has to be some totally different name.

@sqlalchemy-bot
Copy link
Collaborator Author

Michael Bayer (@zzzeek) wrote:

anyway nice catch! https://gerrit.sqlalchemy.org/510 it's called .inserted now.

@sqlalchemy-bot
Copy link
Collaborator Author

Michael Bayer (@zzzeek) wrote:

Rename MySQL dml.insert().values to .inserted

Changed the name of the .values attribute of the new MySQL
INSERT..ON DUPLICATE KEY UPDATE construct to .inserted, as
:class:.Insert already has a method called :meth:.Insert.values.
The .inserted attribute ultimately renders the MySQL VALUES()
function.

Change-Id: I8da8e30a3077698385a4b77e2c2032e2d1ff10b2
Fixes: #4072

70be731

@sqlalchemy-bot
Copy link
Collaborator Author

Changes by Michael Bayer (@zzzeek):

  • changed status to closed

@sqlalchemy-bot
Copy link
Collaborator Author

Michael Bayer (@zzzeek) wrote:

thanks, we dodged a bullet on that one. whenever i see a bug report from you I know im going to have to fix something for real... :)

@sqlalchemy-bot
Copy link
Collaborator Author

Jack Zhou (@univerio) wrote:

Happy to help. And thank you for the quick fix as always!

@sqlalchemy-bot sqlalchemy-bot added bug Something isn't working mysql low priority labels Nov 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working low priority mysql
Projects
None yet
Development

No branches or pull requests

1 participant