Skip to content

Commit a0931a4

Browse files
authored
Fix mysqljdbc edge case (#61)
1 parent 5e6ee17 commit a0931a4

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

local_data_api/resources/resource.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,10 @@ def create_connection(
170170
connection = RESOURCE_METAS[resource_arn].connection_maker( # type: ignore
171171
database, **connection_kwargs
172172
)
173-
if hasattr(connection, 'database'): # pragma: no cover
173+
try:
174174
connection.database = database
175+
except AttributeError: # pragma: no cover
176+
pass # for psycopg2
175177
return connection
176178

177179

@@ -210,12 +212,12 @@ def get_resource(
210212
else:
211213
connection = get_connection(transaction_id)
212214
if database:
213-
if hasattr(connection, 'database'): # pragma: no cover
215+
try:
214216
connected_database: Optional[str] = connection.database
215-
else:
216-
connected_database = connection.get_dsn_parameters()[
217+
except AttributeError: # pragma: no cover
218+
connected_database = connection.get_dsn_parameters()[ # for psycopg2
217219
'dbname'
218-
] # pragma: no cover
220+
]
219221
if database != connected_database: # pragma: no cover
220222
raise BadRequestException(
221223
'Database name is not the same as when transaction was created'

0 commit comments

Comments
 (0)