with_alias in select causes non-aliased fields to become nested under their tablename
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 45/100
Research direction
Start with the runnable Python reproduction in the issue and inspect pydal/objects.py, especially Row.getattr and getitem, where the traceback points. Confirm the behavior with and without with_alias(); done means non-aliased fields remain accessible alongside aliased fields in the resulting row.
Written by the indexing model from the issue text.
Description
Using with_alias() in .select causes non-aliasd fields to be inaccessible on the resulting row:
Without alias, this works:
rows = db().select(db.mytable.field1, db.mytable.field2)
row = next(iter(rows))
print(row) # <Row {'field1': 'A', 'field2': 'B'}>
row.field1
With alias, this fails with AttributeError during handling of KeyError:
rows = db().select(db.mytable.field1, db.mytable.field2.with_alias("field_two"))
row = next(iter(rows))
print(row) # <Row {'mytable': {'field1': 'A'}, 'field_two': 'B', '_extra': {'"mytable"."field2" AS field_two': 'B'}}>
row.field1
Error caused:
Traceback (most recent call last):
File ".venv\lib\site-packages\pydal\objects.py", line 167, in __getattr__
return self.__getitem__(k)
File ".venv\lib\site-packages\pydal\objects.py", line 147, in __getitem__
raise KeyError(key)
KeyError: 'field1'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "test.py", line 16, in <module>
row.field1
File ".venv\lib\site-packages\pydal\objects.py", line 169, in __getattr__
raise AttributeError
AttributeError
version:
>>> pydal.__version__
'20241111.2'
Full runnable reproduction
from pydal import DAL, Field
db = DAL("sqlite:memory")
db.define_table("mytable", Field("field1"), Field("field2"))
db.mytable.insert(field1="A", field2="B")
rows = db().select(db.mytable.field1, db.mytable.field2)
row = next(iter(rows))
print(row)
row.field1
rows = db().select(db.mytable.field1, db.mytable.field2.with_alias("field_two"))
row = next(iter(rows))
print(row)
row.field1
- Dominant language
- Python
- Stars
- 540
- Forks
- 151
- Avg merge
- 12d 14h
- Merged PRs (30d)
- 1
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from web2py/pydal
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
-
Difficulty 3/5 1-2 days Newbie friendliness 50/100
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
Library sweep logs an ERROR at start for the valkey instrumentor when valkey-py is not installedOpen
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
bug good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
JoahanMorales/upiixia-agentic-kit#99 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 1/5 Under an hour Newbie friendliness 85/100
NatLabRockies/openstudio-mcp#286 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100