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

bpo-40956: Convert sqlite3.connect and sqlite3.Connection.__init__ to AC #24421

Merged
merged 17 commits into from
Jun 20, 2021

Conversation

erlend-aasland
Copy link
Contributor

@erlend-aasland erlend-aasland commented Feb 2, 2021

@erlend-aasland
Copy link
Contributor Author

FYI, rebased onto master.

@berkerpeksag
Copy link
Member

FYI, this is on my TODO list, but I want to take my time to review it since AC PRs tend to introduce regressions because of our lack of test coverage in this area.

@erlend-aasland
Copy link
Contributor Author

FYI, this is on my TODO list, but I want to take my time to review it since AC PRs tend to introduce regressions because of our lack of test coverage in this area.

I can take a look at the code coverage later today. If it's possible to increase it by extending the unit test suite, we should do so first.

@berkerpeksag
Copy link
Member

I don't think we have a lot of tests for optional or keyword arguments of public APIs. #24503 is a recent example of a regression introduced due to lack of tests.

@erlend-aasland
Copy link
Contributor Author

erlend-aasland commented Feb 21, 2021

I don't think we have a lot of tests for optional or keyword arguments of public APIs. #24503 is a recent example of a regression introduced due to lack of tests.

Exactly. As far as I can see, all arguments are covered except check_same_thread. Let's add a test for that before continuing.

EDIT: database keyword is also not tested.

@erlend-aasland
Copy link
Contributor Author

@berkerpeksag This will do the trick for check_same_thread:

diff --git a/Lib/sqlite3/test/dbapi.py b/Lib/sqlite3/test/dbapi.py
index 39c9bf5b61..050094f895 100644
--- a/Lib/sqlite3/test/dbapi.py
+++ b/Lib/sqlite3/test/dbapi.py
@@ -533,6 +533,20 @@ def tearDown(self):
         self.cur.close()
         self.con.close()
 
+    def test_dont_check_same_thread(self):
+        def run(con, err):
+            try:
+                cur = con.execute("select 1")
+            except sqlite.Error:
+                err.append("multi-threading not allowed")
+
+        con = sqlite.connect(":memory:", check_same_thread=False)
+        err = []
+        t = threading.Thread(target=run, kwargs={"con": con, "err": err})
+        t.start()
+        t.join()
+        self.assertEqual(len(err), 0, "\n".join(err))
+
     def test_con_cursor(self):
         def run(con, errors):
             try:

BTW, ThreadTests could need a clean-up...

@erlend-aasland
Copy link
Contributor Author

erlend-aasland commented Mar 8, 2021

@berkerpeksag Can I add tests for the database and check_same_thread keywords, or do you want that in a separate PR?

UPDATE: Tests complementing keyword coverage has been added.

@github-actions
Copy link

github-actions bot commented Apr 8, 2021

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions bot added the stale Stale PR or inactive for long period of time. label Apr 8, 2021
@erlend-aasland erlend-aasland removed the stale Stale PR or inactive for long period of time. label May 7, 2021
@erlend-aasland
Copy link
Contributor Author

Rebased onto main to resolve conflicts.

@erlend-aasland erlend-aasland marked this pull request as draft June 6, 2021 19:52
@erlend-aasland erlend-aasland marked this pull request as ready for review June 6, 2021 20:41
detect_types: int = 0
isolation_level: object = NULL
check_same_thread: bool(accept={int}) = True
factory: object(c_default='(PyObject*)clinic_state()->ConnectionType') = ConnectionType
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hummmm, i don't fully get how this is preserving the state as before. Seems that the previous code didn't have a default for factory and used NULL as the c default. Could you briefly explain how this default is preserving previous behaviour?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure :) This is the current code:

if (factory == NULL) {
pysqlite_state *state = pysqlite_get_state(self);
factory = (PyObject *)state->ConnectionType;
}

In practice, the factory default is ConnectionType, not NULL, so I chose to let AC take care of this instead of writing it out explicitly in the function body. This also aligns well with the documentation, which says that factory defaults to the sqlite3.Connection type.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see. Is other code using this branch in module.c:92? I winder if we can enforce that a factory is always provided after this PR

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is other code using this branch in module.c:92?

Not in the stdlib (except for some tests in the test suite), but I guess it's used in the wild. Personally, I would not have added this feature in the first place.

I winder if we can enforce that a factory is always provided after this PR

That's kind of what we're doing no with the default AC argument, right?

@erlend-aasland erlend-aasland requested a review from pablogsal June 17, 2021 21:24
@erlend-aasland
Copy link
Contributor Author

Not sure what's wrong with the "check generated files" CI; the last commit did not touch the clinic code in any way. I did a make patchcheck, and it does not complain. Maybe a spurious CI error?

@pablogsal
Copy link
Member

You are changing the AC and either there are some changes you did and you didn't regenerate or as subset of the files in the main branch has moved since then and therefore your files are not up to date.

@erlend-aasland
Copy link
Contributor Author

erlend-aasland commented Jun 17, 2021

You are changing the AC and either there are some changes you did and you didn't regenerate or as subset of the files in the main branch has moved since then and therefore your files are not up to date.

Commit af0fc7e passed the CI perfectly. All 98f1a9d did was adding two C comments (out of clinic scope). make clinic produces nothing. I'll merge in main and see if that helps. UPDATE: Either that did the trick, or it was a spurious CI error.

@erlend-aasland
Copy link
Contributor Author

Let me know if you want further changes, @pablogsal.

@pablogsal
Copy link
Member

Great job @erlend-aasland! and thanks for the patience! 🚀

@pablogsal pablogsal merged commit 185ecdc into python:main Jun 20, 2021
@erlend-aasland erlend-aasland deleted the bpo-40956/finale branch June 20, 2021 20:20
@erlend-aasland
Copy link
Contributor Author

Great job @erlend-aasland! and thanks for the patience! 🚀

Many thanks, Pablo!

erlend-aasland pushed a commit that referenced this pull request Jul 23, 2022
…ctory (#95146)

This PR partially reverts gh-24421 (PR) and fixes the remaining concerns
given in gh-93044 (issue):

- keyword arguments are passed as positional arguments to factory()
- if an argument is not passed to sqlite3.connect(), its default value
  is passed to factory()

Co-authored-by: Serhiy Storchaka <[email protected]>
erlend-aasland pushed a commit to erlend-aasland/cpython that referenced this pull request Jul 23, 2022
…connect to factory (pythonGH-95146)

This PR partially reverts pythongh-24421 (PR) and fixes the remaining concerns
given in pythongh-93044 (issue):

- keyword arguments are passed as positional arguments to factory()
- if an argument is not passed to sqlite3.connect(), its default value
  is passed to factory()

Co-authored-by: Serhiy Storchaka <[email protected]>.
(cherry picked from commit a3d4d15)

Co-authored-by: Erlend Egeberg Aasland <[email protected]>
erlend-aasland pushed a commit that referenced this pull request Jul 23, 2022
…t to factory (GH-95146) (#95158)

This PR partially reverts gh-24421 (PR) and fixes the remaining concerns
given in gh-93044 (issue):

- keyword arguments are passed as positional arguments to factory()
- if an argument is not passed to sqlite3.connect(), its default value
  is passed to factory()

Co-authored-by: Serhiy Storchaka <[email protected]>.
(cherry picked from commit a3d4d15)

Co-authored-by: Erlend Egeberg Aasland <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants