Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use SQLAlchemy 2.x execution API #388

Merged
merged 6 commits into from
Jan 27, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .github/workflows/ci-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,19 @@ jobs:
- run: pip install tox
- name: Running tox
run: tox -e py37-pyramid19
test-sqlalchemy14:
runs-on: ubuntu-latest
name: "Python: 3.11-x64 on ubuntu-latest with SQLAlchemy 1.4"
steps:
- uses: actions/checkout@v4
- name: Setup python
uses: actions/setup-python@v4
with:
python-version: 3.11
architecture: x64
- run: pip install tox
- name: Running tox
run: tox -e py311-sqlalchemy14
coverage:
runs-on: ubuntu-latest
name: Validate coverage
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,4 @@ Contributors
- Marcin Lulek, 2018-02-19
- Wim De Clercq, 2018-11-23
- Holger Peters, 2020-02-06
- Nicholas Pilon, 2024-01-05
32 changes: 17 additions & 15 deletions src/pyramid_debugtoolbar/panels/sqla.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,14 +229,15 @@ def sql_select(self):

engines = self.request.registry.parent_registry.pdtb_sqla_engines
engine = engines[int(engine_id)]()
result = engine.execute(stmt, params)
with engine.connect() as connection:
result = connection.exec_driver_sql(stmt, params)

return {
'result': result.fetchall(),
'headers': result.keys(),
'sql': format_sql(stmt),
'duration': float(query_dict['duration']),
}
return {
'result': result.fetchall(),
'headers': result.keys(),
'sql': format_sql(stmt),
'duration': float(query_dict['duration']),
}

@view_config(
route_name='debugtoolbar.sql_explain',
Expand All @@ -261,15 +262,16 @@ def sql_explain(self):
else:
query = 'EXPLAIN %s' % stmt

result = engine.execute(query, params)
with engine.connect() as connection:
result = connection.exec_driver_sql(query, params)

return {
'result': result.fetchall(),
'headers': result.keys(),
'sql': format_sql(stmt),
'str': str,
'duration': float(query_dict['duration']),
}
return {
'result': result.fetchall(),
'headers': result.keys(),
'sql': format_sql(stmt),
'str': str,
'duration': float(query_dict['duration']),
}


def includeme(config):
Expand Down
1 change: 0 additions & 1 deletion tests/test_panels/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ def ok_response_factory():


class _TestDebugtoolbarPanel(unittest.TestCase):

re_toolbar_link = re_toolbar_link

def setUp(self):
Expand Down
1 change: 0 additions & 1 deletion tests/test_panels/test_request_vars.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ def templated_escaped(input, expect_saferepr=None):

class _TestPanel_RequestVars(_TestDebugtoolbarPanel):
def _makeOne(self, query_args=None, post_body=None, content_type=None):

# make a request
query_args = ("?=%s" % urlencode(query_args)) if query_args else ""
kwargs = {}
Expand Down
2 changes: 2 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ deps =
pyramid18: pyramid <= 1.8.99
pyramid19: pyramid <= 1.9.99
pyramid110: pyramid <= 1.10.99
sqlalchemy14: sqlalchemy < 2.0
sqlalchemy20: sqlalchemy >= 2.0, <2.1

commands =
py.test --cov --cov-report= {posargs:}
Expand Down
Loading