crate / sqlalchemy-cratedb

SQLAlchemy dialect for CrateDB.
https://cratedb.com/docs/sqlalchemy-cratedb/
Apache License 2.0
3 stars 2 forks source link

sqlalchemy update in python 3.5 #127

Closed Negashev closed 7 years ago

Negashev commented 7 years ago

I have model User

# __init__.py
from flask_sqlalchemy import SQLAlchemy

from server import app

db = SQLAlchemy(app)

from server.db.models import User

db.create_all()
# models.py
class User(db.Model):
    __tablename__ = 'users'
    mail = db.Column(db.String, primary_key=True)
    img = db.Column(db.String)

    def __init__(self, mail):
        self.mail = mail
        self.img = hashlib.md5(mail.encode()).hexdigest()

    def __repr__(self):
        return '<User %r>' % self.mail

When i try to update on row, i get error

>>> import server.db as h
>>> s=h.models.User.query.filter_by(mail='i@negash.ru').first()
>>> s.img='965fe6f7e5727271c4c67fc43f325288_NEW_DATA'
>>> h.db.session.commit()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.5/site-packages/sqlalchemy/orm/scoping.py", line 157, in do
    return getattr(self.registry(), name)(*args, **kwargs)
  File "/usr/local/lib/python3.5/site-packages/sqlalchemy/orm/session.py", line 874, in commit
    self.transaction.commit()
  File "/usr/local/lib/python3.5/site-packages/sqlalchemy/orm/session.py", line 461, in commit
    self._prepare_impl()
  File "/usr/local/lib/python3.5/site-packages/sqlalchemy/orm/session.py", line 441, in _prepare_impl
    self.session.flush()
  File "/usr/local/lib/python3.5/site-packages/sqlalchemy/orm/session.py", line 2137, in flush
    self._flush(objects)
  File "/usr/local/lib/python3.5/site-packages/sqlalchemy/orm/session.py", line 2257, in _flush
    transaction.rollback(_capture_exception=True)
  File "/usr/local/lib/python3.5/site-packages/sqlalchemy/util/langhelpers.py", line 60, in __exit__
    compat.reraise(exc_type, exc_value, exc_tb)
  File "/usr/local/lib/python3.5/site-packages/sqlalchemy/util/compat.py", line 186, in reraise
    raise value
  File "/usr/local/lib/python3.5/site-packages/sqlalchemy/orm/session.py", line 2221, in _flush
    flush_context.execute()
  File "/usr/local/lib/python3.5/site-packages/sqlalchemy/orm/unitofwork.py", line 389, in execute
    rec.execute(self)
  File "/usr/local/lib/python3.5/site-packages/sqlalchemy/orm/unitofwork.py", line 548, in execute
    uow
  File "/usr/local/lib/python3.5/site-packages/sqlalchemy/orm/persistence.py", line 172, in save_obj
    mapper, table, update)
  File "/usr/local/lib/python3.5/site-packages/sqlalchemy/orm/persistence.py", line 732, in _emit_update_statements
    execute(statement, multiparams)
  File "/usr/local/lib/python3.5/site-packages/sqlalchemy/engine/base.py", line 945, in execute
    return meth(self, multiparams, params)
  File "/usr/local/lib/python3.5/site-packages/sqlalchemy/sql/elements.py", line 263, in _execute_on_connection
    return connection._execute_clauseelement(self, multiparams, params)
  File "/usr/local/lib/python3.5/site-packages/sqlalchemy/engine/base.py", line 1015, in _execute_clauseelement
    fn(self, elem, multiparams, params)
  File "/usr/local/lib/python3.5/site-packages/crate/client/sqlalchemy/compiler.py", line 88, in crate_before_execute
    return rewrite_update(clauseelement, multiparams, params)
  File "/usr/local/lib/python3.5/site-packages/crate/client/sqlalchemy/compiler.py", line 64, in rewrite_update
    for key, val in _params.items():
AttributeError: 'list' object has no attribute 'items'

use docker image

FROM python:3-alpine
RUN pip install flask
RUN pip install flask-sqlalchemy
RUN pip install crate
mfussenegger commented 7 years ago

thanks for reporting, we'll take a look at this

mikethebeer commented 7 years ago

@Negashev issue has been fixed and applied in 0.16.5 which got already released. Have fun and thanks for reporting. 👍