Updating sqlalchemy_django_query to sqlalchemy 1.4

89 views
Skip to first unread message

Piotr

unread,
May 19, 2021, 7:19:47 AM5/19/21
to sqlalchemy
I'm trying to update this Query class mixin - https://github.com/mitsuhiko/sqlalchemy-django-query/blob/master/sqlalchemy_django_query.py to sqlalchemy 1.4.

Aside of joinedload_all removed the Query class changes a lot which breaks the:

column = _entity_descriptor(q._joinpoint_zero(), token)

as "_joinpoint_zero" is no longer present in that class. I've tried like looping over _raw_columns (simplified below):

column = _entity_descriptor(get_mapper(self._raw_columns[0]), token)

Which works for some cases - like it finds backward relationship but then fails to map a field from child as _raw_columns contain only the parent.

How this could be migrated to 1.4? It's a dependency for flask_jsonapi that either way would be hard to remove and replace with some custom parser for filters, ordering and pagination.

Mike Bayer

unread,
May 19, 2021, 7:41:07 PM5/19/21
to noreply-spamdigest via sqlalchemy
the _joinpoint_zero() can likely be replaced by _filter_by_zero() : https://github.com/sqlalchemy/sqlalchemy/blob/master/lib/sqlalchemy/orm/query.py#L1697

I had mentioned this to someone on twitter but they never got back to me if it worked or not.
--
SQLAlchemy -
The Python SQL Toolkit and Object Relational Mapper
 
 
To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description.
---
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+...@googlegroups.com.

piotr maliński

unread,
May 20, 2021, 4:35:57 AM5/20/21
to sqlal...@googlegroups.com

I used self._compile_state()._joinpoint_zero() while self._filter_by_zero() also seems to be working.

You received this message because you are subscribed to a topic in the Google Groups "sqlalchemy" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sqlalchemy/OvsP7_vtoMQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sqlalchemy+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sqlalchemy/77e96721-d406-4c13-ab29-69063924238a%40www.fastmail.com.

Mike Bayer

unread,
May 20, 2021, 10:06:33 AM5/20/21
to noreply-spamdigest via sqlalchemy
_compile_state() is an expensive call so you'd want to avoid doing that casually, that's why filter_by_zero is there.

piotr maliński

unread,
May 21, 2021, 8:31:48 AM5/21/21
to sqlal...@googlegroups.com
I've changed that... local test case passed while some microservices managed to get cases not covered by those tests (like ValueError: Multiple mappers found for table ). Seems like using 10-year old abandoned code that uses SQLAlchemy internals wasn't the best long term idea ;)

Mike Bayer

unread,
May 21, 2021, 9:09:17 AM5/21/21
to noreply-spamdigest via sqlalchemy
I'm pretty sure I wrote that code originally before Armin published it so there you go :)
Reply all
Reply to author
Forward
0 new messages