Skip to content

Commit

Permalink
Fix #1327 OAuth module: SQLAlchemy v2 compatibility (#1335)
Browse files Browse the repository at this point in the history
  • Loading branch information
seratch authored Feb 17, 2023
1 parent 8dc50a8 commit aabe5b9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ def run(self):
# used only under slack_sdk/*_store
"boto3<=2",
# InstallationStore/OAuthStateStore
"SQLAlchemy>=1,<2",
"SQLAlchemy>=1,<3",
# Socket Mode
# websockets 9 is not compatible with Python 3.10
"websockets>=10,<11" if sys.version_info.minor > 6 else "websockets>=9.1,<10",
Expand Down
14 changes: 7 additions & 7 deletions slack_sdk/oauth/installation_store/sqlalchemy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def save(self, installation: Installation):

i_column = self.installations.c
installations_rows = conn.execute(
sqlalchemy.select([i_column.id])
sqlalchemy.select(i_column.id)
.where(
and_(
i_column.client_id == self.client_id,
Expand All @@ -152,7 +152,7 @@ def save(self, installation: Installation):
.limit(1)
)
installations_row_id: Optional[str] = None
for row in installations_rows:
for row in installations_rows.mappings():
installations_row_id = row["id"]
if installations_row_id is None:
conn.execute(self.installations.insert(), i)
Expand All @@ -171,7 +171,7 @@ def save_bot(self, bot: Bot):

b_column = self.bots.c
bots_rows = conn.execute(
sqlalchemy.select([b_column.id])
sqlalchemy.select(b_column.id)
.where(
and_(
b_column.client_id == self.client_id,
Expand All @@ -183,7 +183,7 @@ def save_bot(self, bot: Bot):
.limit(1)
)
bots_row_id: Optional[str] = None
for row in bots_rows:
for row in bots_rows.mappings():
bots_row_id = row["id"]
if bots_row_id is None:
conn.execute(self.bots.insert(), b)
Expand Down Expand Up @@ -217,7 +217,7 @@ def find_bot(

with self.engine.connect() as conn:
result: object = conn.execute(query)
for row in result: # type: ignore
for row in result.mappings(): # type: ignore
return Bot(
app_id=row["app_id"],
enterprise_id=row["enterprise_id"],
Expand Down Expand Up @@ -261,7 +261,7 @@ def find_installation(
installation: Optional[Installation] = None
with self.engine.connect() as conn:
result: object = conn.execute(query)
for row in result: # type: ignore
for row in result.mappings(): # type: ignore
installation = Installation(
app_id=row["app_id"],
enterprise_id=row["enterprise_id"],
Expand Down Expand Up @@ -302,7 +302,7 @@ def find_installation(
query = self.installations.select().where(where_clause).order_by(desc(c.installed_at)).limit(1)
with self.engine.connect() as conn:
result: object = conn.execute(query)
for row in result: # type: ignore
for row in result.mappings(): # type: ignore
installation.bot_token = row["bot_token"]
installation.bot_id = row["bot_id"]
installation.bot_user_id = row["bot_user_id"]
Expand Down
2 changes: 1 addition & 1 deletion slack_sdk/oauth/state_store/sqlalchemy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def consume(self, state: str) -> bool:
c = self.oauth_states.c
query = self.oauth_states.select().where(and_(c.state == state, c.expire_at > datetime.utcnow()))
result = conn.execute(query)
for row in result:
for row in result.mappings():
self.logger.debug(f"consume's query result: {row}")
conn.execute(self.oauth_states.delete().where(c.id == row["id"]))
return True
Expand Down

0 comments on commit aabe5b9

Please sign in to comment.