Skip to content
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

Fix select priority name #525

Merged
merged 4 commits into from
Jan 2, 2019
Merged

Conversation

vir-mir
Copy link
Member

@vir-mir vir-mir commented Jan 1, 2019

Now there is a problem if we want to redefine the field for the database and to work in python.

We have a table, example:

CREATE TABLE sa_tbl5 ("ID" VARCHAR(255) NOT NULL, "Name" VARCHAR(255), PRIMARY KEY ("ID"));

I initialize fields in this way:

meta = sa.MetaData()
tbl = sa.Table(
    'sa_tbl5', meta,
    sa.Column('ID', sa.String, primary_key=True, key='id'),
    sa.Column('Name', sa.String(255), key='name'),
)

Then I insert, with keys id and name, no errors, the record appeared in the database

await connect.execute(tbl.insert().values(id='test_id', name='test_name'))

Problems start when sampling data:

row = await (await connect.execute(tbl.select())).fetchone()
print(dict(row))  # {'ID': 'test_id', 'Name': 'test_name'}
print(row.name)  # AttributeError: Could not locate column in row for column 'name'

The problem is in the broken ResultMetaData, namely in the processing of result_proxy._result_map and _key_fallback.

We have to select a column from the result_proxy._result_map dictionary, and process the key attribute in it stores the current name for working in python or well as alias label.

@asvetlov @jettify will review?

@codecov
Copy link

codecov bot commented Jan 1, 2019

Codecov Report

Merging #525 into master will increase coverage by 0.31%.
The diff coverage is 98.14%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #525      +/-   ##
==========================================
+ Coverage   93.76%   94.08%   +0.31%     
==========================================
  Files          25       26       +1     
  Lines        3756     3804      +48     
  Branches      199      198       -1     
==========================================
+ Hits         3522     3579      +57     
+ Misses        196      186      -10     
- Partials       38       39       +1
Impacted Files Coverage Δ
tests/pep492/test_sa_priority_name.py 100% <100%> (ø)
aiopg/sa/result.py 91.42% <92.85%> (+0.33%) ⬆️
tests/conftest.py 69.44% <0%> (+3.57%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 57b5d55...5e833fb. Read the comment docs.

@vir-mir vir-mir merged commit 862fff9 into aio-libs:master Jan 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants