Repository navigation
Keep the Query Tool execute options when its transaction is re-created. #10598 #10599
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
Closed
dpage
wants to merge
2
commits into
pgadmin-org:master
from
dpage:fix/issue-10598-execute-options-reinit
+220
−5
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
web/pgadmin/tools/sqleditor/tests/test_execute_options_reinit.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| ########################################################################## | ||
| # | ||
| # pgAdmin 4 - PostgreSQL Tools | ||
| # | ||
| # Copyright (C) 2013 - 2026, The pgAdmin Development Team | ||
| # This software is released under the PostgreSQL Licence | ||
| # | ||
| ########################################################################## | ||
|
|
||
| import json | ||
| import pickle | ||
| import secrets | ||
|
|
||
| from pgadmin.browser.server_groups.servers.databases.tests import utils as \ | ||
| database_utils | ||
| from pgadmin.utils.route import BaseTestGenerator | ||
| from regression import parent_node_dict | ||
| from regression.python_test_utils import test_utils as utils | ||
|
|
||
| # The preference defaults, which the freshly created test database uses. | ||
| PREFERENCE_OPTIONS = { | ||
| 'auto_commit': True, | ||
| 'auto_rollback': False, | ||
| 'server_cursor': False, | ||
| } | ||
| CHANGED_OPTIONS = { | ||
| 'auto_commit': False, | ||
| 'auto_rollback': True, | ||
| 'server_cursor': True, | ||
| } | ||
|
|
||
|
|
||
| class TestExecuteOptionsReinit(BaseTestGenerator): | ||
| """ | ||
| The execute options chosen on the Query Tool toolbar must be kept when | ||
| the transaction is re-created, rather than reset to the preferences | ||
| (issue #10598). | ||
| """ | ||
| scenarios = [ | ||
| ('Initialise with the toolbar execute options', dict( | ||
| change_connection=False, init_options=CHANGED_OPTIONS, | ||
| expected=CHANGED_OPTIONS)), | ||
| ('Initialise with some of the toolbar execute options', dict( | ||
| change_connection=False, | ||
| init_options={'server_cursor': True}, | ||
| expected=dict(PREFERENCE_OPTIONS, server_cursor=True))), | ||
| ('Initialise without execute options uses the preferences', dict( | ||
| change_connection=False, init_options={}, | ||
| expected=PREFERENCE_OPTIONS)), | ||
| ('Initialise ignores execute options that are not booleans', dict( | ||
| change_connection=False, | ||
| init_options={'auto_commit': 'false', 'auto_rollback': None, | ||
| 'server_cursor': 1}, | ||
| expected=PREFERENCE_OPTIONS)), | ||
| ('Changing the connection keeps the execute options', dict( | ||
| change_connection=True, init_options={}, | ||
| toolbar_options=CHANGED_OPTIONS, expected=CHANGED_OPTIONS)), | ||
| ('Changing the connection ignores execute options that are not ' | ||
| 'booleans', dict( | ||
| change_connection=True, init_options={}, | ||
| toolbar_options={'auto_commit': 'false', 'auto_rollback': 1, | ||
| 'server_cursor': 1}, | ||
| expected=PREFERENCE_OPTIONS)), | ||
| ] | ||
|
|
||
| def setUp(self): | ||
| database_info = parent_node_dict["database"][-1] | ||
| self.db_name = database_info["db_name"] | ||
| self.server_id = database_info["server_id"] | ||
| self.db_id = database_info["db_id"] | ||
| db_con = database_utils.connect_database(self, | ||
| utils.SERVER_GROUP, | ||
| self.server_id, | ||
| self.db_id) | ||
| if not db_con["info"] == "Database connected.": | ||
| raise Exception("Could not connect to the database.") | ||
|
|
||
| self.trans_id = str(secrets.choice(range(1, 9999999))) | ||
| url = '/sqleditor/initialize/sqleditor/{0}/{1}/{2}/{3}'.format( | ||
| self.trans_id, utils.SERVER_GROUP, self.server_id, self.db_id) | ||
| response = self.tester.post(url, data=json.dumps(dict( | ||
| self.init_options, dbname=self.db_name))) | ||
| self.assertEqual(response.status_code, 200) | ||
|
|
||
| def runTest(self): | ||
| if self.change_connection: | ||
| # Change the options from the toolbar, then change the | ||
| # connection, which creates a new transaction. | ||
| for option, value in self.toolbar_options.items(): | ||
| response = self.tester.post( | ||
| '/sqleditor/{0}/{1}'.format(option, self.trans_id), | ||
| data=json.dumps(value)) | ||
| self.assertEqual(response.status_code, 200) | ||
|
|
||
| url = ('/sqleditor/initialize/sqleditor/update_connection/' | ||
| '{0}/{1}/{2}/{3}').format(self.trans_id, | ||
| utils.SERVER_GROUP, | ||
| self.server_id, self.db_id) | ||
| response = self.tester.post(url, data=json.dumps({ | ||
| 'user': self.server['username'], | ||
| 'role': None, | ||
| 'password': self.server['db_password'], | ||
| 'database_name': self.db_name, | ||
| }), content_type='html/json') | ||
| self.assertEqual(response.status_code, 200) | ||
| self.trans_id = json.loads( | ||
| response.data.decode('utf-8'))['data']['trans_id'] | ||
|
|
||
| with self.tester.session_transaction() as sess: | ||
| command_obj = pickle.loads( | ||
| sess['gridData'][str(self.trans_id)]['command_obj']) | ||
|
|
||
| for option, value in self.expected.items(): | ||
| self.assertIs(getattr(command_obj, option), value, option) | ||
|
|
||
| def tearDown(self): | ||
| self.tester.delete('/sqleditor/close/{0}'.format(self.trans_id)) | ||
| database_utils.disconnect_database(self, self.server_id, self.db_id) |
68 changes: 68 additions & 0 deletions
68
web/regression/javascript/sqleditor/QueryToolInitialise.spec.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| ///////////////////////////////////////////////////////////// | ||
| // | ||
| // pgAdmin 4 - PostgreSQL Tools | ||
| // | ||
| // Copyright (C) 2013 - 2026, The pgAdmin Development Team | ||
| // This software is released under the PostgreSQL Licence | ||
| // | ||
| ////////////////////////////////////////////////////////////// | ||
|
|
||
| // QueryToolComponent.jsx pulls in editors and viewers that this test never | ||
| // renders, and whose ESM-only dependencies Jest cannot load. | ||
| jest.mock('../../../pgadmin/static/js/components/ReactCodeMirror', () => ({ | ||
| __esModule: true, | ||
| default: ({ value }) => value, | ||
| })); | ||
| jest.mock('../../../pgadmin/static/js/components/JsonEditor', () => ({ | ||
| __esModule: true, | ||
| default: () => null, | ||
| })); | ||
| jest.mock('../../../pgadmin/tools/sqleditor/static/js/components/sections/GeometryViewer', () => ({ | ||
| GeometryViewer: () => null, | ||
| })); | ||
| jest.mock('../../../pgadmin/tools/sqleditor/static/js/components/sections/GraphVisualiser', () => ({ | ||
| GraphVisualiser: () => null, | ||
| })); | ||
|
|
||
| import { getInitialiseRequestData } from '../../../pgadmin/tools/sqleditor/static/js/components/QueryToolComponent.jsx'; | ||
|
|
||
| const connParams = { | ||
| user: 'postgres', | ||
| role: null, | ||
| password: '', | ||
| dbname: 'postgres', | ||
| }; | ||
|
|
||
| describe('getInitialiseRequestData', () => { | ||
| it('sends the toolbar execute options for a Query Tool', () => { | ||
| expect(getInitialiseRequestData({is_query_tool: true}, connParams, { | ||
| auto_commit: false, | ||
| auto_rollback: true, | ||
| server_cursor: true, | ||
| explain_verbose: true, | ||
| open_in_new_tab: false, | ||
| })).toEqual({ | ||
| ...connParams, | ||
| auto_commit: false, | ||
| auto_rollback: true, | ||
| server_cursor: true, | ||
| }); | ||
| }); | ||
|
|
||
| it('leaves out execute options that are not known yet', () => { | ||
| expect(getInitialiseRequestData({is_query_tool: true}, connParams, null)) | ||
| .toEqual(connParams); | ||
| expect(getInitialiseRequestData({is_query_tool: true}, connParams, {})) | ||
| .toEqual(connParams); | ||
| expect(getInitialiseRequestData({is_query_tool: true}, connParams, { | ||
| auto_commit: undefined, server_cursor: false, | ||
| })).toEqual({...connParams, server_cursor: false}); | ||
| }); | ||
|
|
||
| it('does not send the toolbar execute options for View/Edit Data', () => { | ||
| expect(getInitialiseRequestData({ | ||
| is_query_tool: false, sql_filter: 'id > 1', server_cursor: true, | ||
| }, connParams, {auto_commit: false, auto_rollback: true, server_cursor: false})) | ||
| .toEqual({...connParams, sql_filter: 'id > 1', server_cursor: true}); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.