Skip to content

Commit f5e74cb

Browse files
authored
Merge pull request StackStorm-Exchange#2 from EncoreTechnologies/hotfix/sql-updates-fixes
SQLAlchemy fixes
2 parents 08648eb + 105f3ea commit f5e74cb

5 files changed

Lines changed: 21 additions & 30 deletions

File tree

CHANGES.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Change Log
22

3+
## 1.1.4
4+
5+
- Fixed several install and run issues related to updates to SQLAlchemy
6+
Contributed by Bradley Bishop (Encore Technologies)
7+
38
## 1.1.3
49

510
- Added the ability to return rows if there were results to return from procedure call.

actions/generic_query.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from lib.base_action import BaseAction
2+
from sqlalchemy import text
23

34

45
class SQLQueryAction(BaseAction):
@@ -18,9 +19,10 @@ def run(self, **kwargs):
1819

1920
query = self.get_del_arg('query', kwargs_dict)
2021

22+
return_result = None
2123
with self.db_connection(kwargs_dict) as conn:
2224
# Execute the query
23-
query_result = conn.exec_driver_sql(query)
25+
query_result = conn.execute(text(query))
2426

2527
# We need to execute these commands while connection is still open.
2628
return_result = {'affected_rows': query_result.rowcount}
@@ -32,8 +34,4 @@ def run(self, **kwargs):
3234
# Convert that to a dictionary for return
3335
return_result.append(self.row_to_dict(row))
3436

35-
return return_result
36-
37-
# If The with is broken or crashes for some reason
38-
# we return an False (error) with None as the data
39-
return (False, None)
37+
return return_result

actions/lib/base_action.py

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ def row_to_dict(self, row):
6161
returns: dictionary of values
6262
"""
6363
return_dict = {}
64-
for column in row._asdict().keys():
65-
value = getattr(row, column)
64+
for column in row._mapping.keys():
65+
value = row._mapping[column]
6666

6767
if isinstance(value, datetime.date):
6868
return_dict[column] = value.isoformat()
@@ -114,6 +114,10 @@ def build_connection(self, kwargs_dict):
114114
default_driver = DEFAULT_KNOWN_DRIVER_CONNECTORS.get(connection['drivername'], None)
115115
if default_driver:
116116
connection['drivername'] = default_driver
117+
118+
# Fix issue with required query param
119+
# https://docs.sqlalchemy.org/en/20/core/engines.html#sqlalchemy.engine.URL.query
120+
connection['query'] = {}
117121

118122
# Format the connection string
119123
return URL(**connection)
@@ -123,24 +127,8 @@ def db_connection(self, kwargs_dict):
123127
"""Connect to the database and instantiate necessary methods to be used
124128
later.
125129
"""
126-
# Get the connection details from either config or from action params
127-
connection = self.resolve_connection(kwargs_dict)
128-
129-
# Update Driver with a connector
130-
default_driver = DEFAULT_KNOWN_DRIVER_CONNECTORS.get(connection['drivername'], None)
131-
if default_driver:
132-
connection['drivername'] = default_driver
133-
134-
# Check if query is in de connection
135-
# We use a immutabledict as required by the documentation of sqlalchemy instead of a tuple.
136-
# Because sqlalchemy made for this funtions its own 'datatype' that it knows how to handle.
137-
# Aimes to be compatible with tuple but not fully.
138-
# https://www.programcreek.com/python/example/58798/sqlalchemy.util.immutabledict
139-
if 'query' not in connection:
140-
connection['query'] = sqlalchemy.util.immutabledict()
141-
142130
# Format the connection string
143-
database_connection_string = URL(**connection)
131+
database_connection_string = self.build_connection(kwargs_dict)
144132

145133
self.engine = sqlalchemy.create_engine(database_connection_string, echo=False)
146134
self.meta = sqlalchemy.MetaData()

pack.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ keywords:
66
- Postgres
77
- MySQL
88
- MsSQL
9-
version: 1.1.3
9+
version: 1.1.4
1010
author: Encore Technologies
1111
email: code@encore.tech
1212
python_versions:

requirements.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
sqlalchemy~=2.0.3
2-
psycopg2 <=2.8
1+
psycopg2-binary<=2.8.6
2+
sqlalchemy
33
pymysql
4-
pymssql<3.0
4+
pymssql==2.2.11
55
cx_Oracle<=7.3.0
6-
fdb
6+
fdb

0 commit comments

Comments
 (0)