summaryrefslogtreecommitdiff
path: root/test/sql
diff options
context:
space:
mode:
authorAndy Freeland <andy@andyfreeland.net>2023-04-20 13:41:39 -0400
committerFederico Caselli <cfederico87@gmail.com>2023-04-20 20:55:21 +0200
commitc1125288e3c413d868070995b308085d2ddf402e (patch)
treecb8e1e04ed56a67d7ddd9bd19c2e727206fa95c1 /test/sql
parentfc2bcead435a9bf0a2de8e9b15a1bd835f9d7fe4 (diff)
downloadsqlalchemy-c1125288e3c413d868070995b308085d2ddf402e.tar.gz
Fix `RowMapping`'s `Mapping` type to reflect that it supports `Column`s or strings
### Description I ran into this originally in sqlalchemy2-stubs: https://github.com/sqlalchemy/sqlalchemy2-stubs/pull/251, where `RowMapping` only supported string keys according to the type hints. I ran into a similar issue here upgrading our application where because `RowMapping` subclassed `Mapping[str, Any]`, `Row._mapping.get()` would fail to typecheck when used with `Column` objects. This patch adds a test to verify that `Row._mapping.get()` continues to work with both strings and `Column`s, though it doesn't look like mypy checks types in the tests. Fixes #9644. ### Checklist <!-- go over following points. check them with an `x` if they do apply, (they turn into clickable checkboxes once the PR is submitted, so no need to do everything at once) --> This pull request is: - [ ] A documentation / typographical error fix - Good to go, no issue or tests are needed - [x] A short code fix - please include the issue number, and create an issue if none exists, which must include a complete example of the issue. one line code fixes without an issue and demonstration will not be accepted. - Please include: `Fixes: #<issue number>` in the commit message - please include tests. one line code fixes without tests will not be accepted. - [ ] A new feature implementation - please include the issue number, and create an issue if none exists, which must include a complete example of how the feature would look. - Please include: `Fixes: #<issue number>` in the commit message - please include tests. **Have a nice day!** Closes: #9643 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/9643 Pull-request-sha: 6c33fe534cf457d6b5c73f4830a64880830f0f56 Change-Id: I1009c6defff109d73f13a9e8c51641009e6a79e2
Diffstat (limited to 'test/sql')
-rw-r--r--test/sql/test_resultset.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/test/sql/test_resultset.py b/test/sql/test_resultset.py
index 0537dc228..e382a7fb6 100644
--- a/test/sql/test_resultset.py
+++ b/test/sql/test_resultset.py
@@ -1595,6 +1595,15 @@ class CursorResultTest(fixtures.TablesTest):
r = connection.exec_driver_sql("select user_name from users").first()
eq_(len(r), 1)
+ def test_row_mapping_get(self, connection):
+ users = self.tables.users
+
+ connection.execute(users.insert(), dict(user_id=1, user_name="foo"))
+ result = connection.execute(users.select())
+ row = result.first()
+ eq_(row._mapping.get("user_id"), 1)
+ eq_(row._mapping.get(users.c.user_id), 1)
+
def test_sorting_in_python(self, connection):
users = self.tables.users