feat: add truncate argument to todb function - #707
Conversation
PR Summary by QodoAdd optional truncation control to
AI Description
Diagram
High-Level Assessment
Files changed (3)
|
Code Review by Qodo
1. Temporary database file leaks
|
| f = NamedTemporaryFile(delete=False) | ||
| conn = sqlite3.connect(f.name) |
There was a problem hiding this comment.
1. Temporary database file leaks 🐞 Bug ☼ Reliability
The new SQLite test creates a NamedTemporaryFile(delete=False) but never closes its file object explicitly or removes its path; closing only the SQLite connection leaves a database artifact after every test run. Repeated or parallel runs therefore accumulate temporary files and rely on nondeterministic cleanup of the original handle.
Agent Prompt
## Issue description
The new SQLite round-trip test creates a named temporary file with deletion disabled, but only closes the SQLite connection. The temporary database remains on disk, and the original temporary-file handle is not explicitly closed.
## Issue Context
Preserve the current assertions while making resource cleanup deterministic, including when setup, database operations, or assertions fail. A pytest temporary-path fixture or a `try`/`finally` that closes both handles and unlinks the file would address the leak.
## Fix Focus Areas
- petl/test/io/test_db.py[128-151]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
Coverage Report for CI Build 32783092771Coverage increased (+0.01%) to 91.912%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
Closes #669.
This PR has the objective of making the truncate step in
todb()optional, so you can load into an existing table without first deleting its rows.As @juarezr pointed out on the issue,
todb()andappenddb()already share the internal_todb()and only differ by thetruncateflag, so this just surfaces that flag ontodb()with a default ofTrueto keep the current behavior unchanged. Passingtruncate=Falsenow appends instead, same asappenddb().Changes
truncatekeyword argument totodb(), defaulting toTrue._todb()call instead of the previously hard-codedTrue.todb()docstring to describe the new argument and the append case.truncate=Falsepassthrough, and an sqlite round trip that keeps existing rows.docs/changes.rst.Testing
.venv/bin/python -m pytest petl/test/io/test_db.pyResult:
12 passed, 2 warningsThe two warnings are the existing sqlite generator cleanup warnings from
test_fromdb, they show up on master too.Checklist
Use this checklist to ensure the quality of pull requests that include new code and/or make changes to existing code.
tox/pytestmasterbranch and tested before sending the PR