Skip to content

SQLAlchemy OAuth module: 'ResultProxy' object has no attribute 'mappings' #1337

@uroboro

Description

@uroboro

Summary

Some compatibility with SQLAlchemy v1 was broken when adding compatibility with SQLAlchemy v2 (in #1335 for slackapi/bolt-python#822).

Overview

I've confirmed that the code works with both v1.4 and v2.0.

From the documentation on SQLAlchemy 1.4:

Changed in version 1.4: The CursorResult and LegacyCursorResult classes replace the previous ResultProxy interface. These classes are based on the Result calling API which provides an updated usage model and calling facade for SQLAlchemy Core and SQLAlchemy ORM.

CursorResult has a mappings() member that ResultProxy does not.

Lastly, setup.py declares compatibility with SQLAlchemy>=1,<3, this caught us off guard.

The code can be updated to support both CursorResult and ResultProxy as the return type of sqlalchemy.engine.Connection.execute with something like the following:

-   for row in result.mappings():
+   for row in (result.mappings() if hasattr(result, "mappings") else result):

for all the similar usages in the PR.

The Slack SDK version

slack-sdk==3.20.0

Python runtime version

3.9.5

Steps to reproduce:

  1. Install slack-sdk==3.20.0 and SQLAlchemy<1.4.0
  2. Deploy service
  3. Receive an event

Expected result:

Process the event.

Actual result:

Traceback (most recent call last):
  File ".../python3.9/site-packages/slack_bolt/app/app.py", line 477, in dispatch
    resp = middleware.process(req=req, resp=resp, next=middleware_next)
  File ".../python3.9/site-packages/slack_bolt/middleware/authorization/multi_teams_authorization.py", line 58, in process
    auth_result: Optional[AuthorizeResult] = self.authorize(
  File ".../python3.9/site-packages/slack_bolt/authorization/authorize.py", line 166, in __call__
    latest_installation: Optional[Installation] = self.installation_store.find_installation(
  File "../python3.9/site-packages/slack_sdk/oauth/installation_store/sqlalchemy/__init__.py", line 264, in find_installation
    for row in result.mappings():  # type: ignore
AttributeError: 'ResultProxy' object has no attribute 'mappings' 

Metadata

Metadata

Assignees

Labels

Version: 3xbugM-T: A confirmed bug report. Issues are confirmed when the reproduction steps are documentedoauth

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions