-
Notifications
You must be signed in to change notification settings - Fork 143
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
pydal-20241204.1 with_alias + as_list broke backward compatibilty with old code. #727
Comments
I found out what changed: Lines 295 to 296 in 16c9395
This now changes colname from "test"."a" as my_col_name to my_col_name That means, later, the following regex match evaluates to None: Lines 307 to 310 in 16c9395
And therefore the last line in that code block never runs. I made a PR which improves the logic a lot, which also fixes this issue for single-table queries. your query would be parsed as this means a multi-table query with both column aliased would result in this, which is still a breaking change: |
Maybe to don't' break old code could be possibile to add a flag in
or something like that that add the same fake table name just to flat multi-table query? |
The intended way to write queries like this would be to either write queries like this: db(db.table1).select(db.table1.id.with_alias("data.tbl1id"), db.table2.id.with_alias("data.tbl2id"), join=db.table2.on(db.table1.id == db.table2.ref_tbl1)) which selects both to a single result table called "data" which will be flattened normally (single table: flat, multi-table: nested, instead of the old "nested but aliases are flat") or just to access the data in its nested form. i'm not sure if @mdipierro has any idea how to resolve this without, essentially, reverting back to the old behaviour entirely |
This monkey patch could be an easy workaround for existing code that doens't support dot notation: from pydal import Field
if not hasattr(Field, 'smart_alias'):
Field.smart_alias = lambda self, fname=None, tname=None: self.with_alias(
f"_.{fname if fname else self.name}" if not tname
else f"{tname}.{fname if fname else self.name}"
) using it:
|
The latest versions of pydal introduced a breaking change in the behavior of the
with_alias
method used withas_list
. In the previous version (20241111.2), when usingwith_alias
withas_list
, the aliased fields were returned as keys of the dict representing the record, but in the latest version, they are only available in the _extra dict.It seems the different behavior is introduced here: 16c9395
This change breaks backward compatibility with existing code that relied on the old behavior.
pydal-20241111.2
pydal-20241204.1
The text was updated successfully, but these errors were encountered: