-
Notifications
You must be signed in to change notification settings - Fork 31
SQLAlchemy deprecation in SqlAlchemyDictTypeTest
#486
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
SQLAlchemy deprecation in SqlAlchemyDictTypeTest
#486
Conversation
values({ | ||
"data['x']": "Trillian" | ||
}) | ||
values({ mytable.c.data['x']: "Trillian" }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks to be valid:
from crate.client.sqlalchemy import types
from sqlalchemy.orm import Session
import sqlalchemy as sa
engine = sa.create_engine("crate://")
metadata_obj = sa.MetaData()
mytable = sa.Table(
"characters",
metadata_obj,
sa.Column("id", sa.String, primary_key=True),
sa.Column("details", types.Object),
autoload_with=engine,
)
session = Session(bind=engine)
session.execute(
mytable.update()
.where(mytable.c.id == "1")
.values({mytable.c.details["x"]: "Trillian"})
)
Resulting query as per sys.jobs_log
: UPDATE characters SET details['x'] = ? WHERE characters.id = ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The previous test might have been wrong, using values({"data['x']": "Trillian"})
throws an exception in a real-world example without any mocking: TypeError: Object of type BindParameter is not JSON serializable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh. Thanks for spotting and investigating diligently.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
throws an exception in a real-world example without any mocking
So, if that did not work before anyway, we will not have to announce anything as "breaking change", right? When looking at this again, I bet this was the spot which may have tripped me in the past already. Thanks again!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added 2c6db67 to make the tests succeed on my end.
c044ede
to
d5cb639
Compare
Don't use `autoload_with` on table `mytable`, because it will never be persisted to a database, so it can not be inspected.
d5cb639
to
2c6db67
Compare
Summary of the changes / Why this is an improvement
@amotl, this is an attempt at fixing the deprecation warning in
SqlAlchemyDictTypeTest
. I'm not 100% sure about thetest_update_with_dict_column
, this would need manual verification.Checklist