Skip to content

v.report: Close null device and command pipes - #8289

Open
Rohan-Dedhia wants to merge 2 commits into
OSGeo:mainfrom
Rohan-Dedhia:fix/8122-v-report-leaks
Open

Rohan-Dedhia wants to merge 2 commits into
OSGeo:mainfrom
Rohan-Dedhia:fix/8122-v-report-leaks

Conversation

@Rohan-Dedhia

Copy link
Copy Markdown
Contributor

Description

  • Replace nuldev = open(os.devnull, "w") in scripts/v.report/v.report.py with subprocess.DEVNULL passed to gs.vector_columns(..., stderr=subprocess.DEVNULL), avoiding an unclosed Python file object (including when gs.find_file exits early via gs.fatal).
  • Wrap all four gs.pipe_command(...) calls (v.db.select, both v.to.db calls, and v.category) in with blocks so their stdout pipes and subprocesses are closed and waited on reliably, including on early exit (gs.fatal when the key column is missing).
  • Remove the now-unused "scripts/v.report/v.report.py" = ["PLW1514"] ignore from pyproject.toml.
  • Add unit tests in scripts/v.report/tests/v_report_test.py covering table mode, no-table mode, fatal early exit during v.db.select iteration, non-zero returncode exit, and real subprocess.Popen cleanup under ResourceWarning tracking.

Motivation and context

Fixes the v.report file and pipe leaks tracked in #8122 (Refs #8122).

How has this been tested?

Ran locally on Windows (Python 3.13.7, without compiled GRASS binaries):

  • python -X dev -W error::ResourceWarning -m pytest scripts/v.report/tests/v_report_test.py -v: 5 passed in 0.46s (using mocked grass.script calls and real subprocess.Popen pipes for resource-warning checks).
  • ruff check scripts/v.report pyproject.toml: All checks passed.
  • ruff check --preview --select SIM115,PLW1514 --isolated scripts/v.report: All checks passed.
  • ruff format --check scripts/v.report: 3 files already formatted.

Full end-to-end execution against compiled GRASS vector modules (v.db.select, v.to.db, v.category) was not run locally and relies on CI.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing
    functionality to not work as before)

Checklist

  • PR title provides summary of the changes and starts with one of the
    pre-defined prefixes
  • My code follows the code style
    of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.

@github-actions github-actions Bot added vector Related to vector data processing Python Related code is in Python module tests Related to Test Suite labels Nov 29, 2026
@Rohan-Dedhia
Rohan-Dedhia force-pushed the fix/8122-v-report-leaks branch from 6c1c648 to c56d270 Compare November 29, 2026 11:46
@Rohan-Dedhia

Copy link
Copy Markdown
Contributor Author

The windows-2022 failure is an external infra flake, not a code regression. Both runs hit HTTP 502 from download.osgeo.org/osgeo4w/v2/x86_64/setup.ini during the OSGeo4W setup step (around 9 minutes in, after all download retries exhausted). This is unrelated to the v.report changes.

All other checks pass: Python Code Quality, build-cmake, gnu17/c++17, ubuntu (24.04), ubuntu temporal, pytest 3.11 on both ubuntu variants, CodeQL, Bandit, Super Linter, codecov, and validate-titles.

Could you re-run the windows-2022 job when you get a chance? Happy to address any code feedback in the meantime. Thanks!

@echoix

echoix commented Nov 29, 2026

Copy link
Copy Markdown
Member

No I won’t rerun right away. The download server flakes on and off since yesterday. Even docker images with geos source code fail to download. I already wrote to the SAC and they tried patching the whole server, but it’s not enough still

@Rohan-Dedhia

Copy link
Copy Markdown
Contributor Author

Understood, thanks for the context! I'll wait for the server situation to resolve. No rush.

@Rohan-Dedhia
Rohan-Dedhia force-pushed the fix/8122-v-report-leaks branch from c56d270 to 504a908 Compare December 3, 2026 14:34
@Rohan-Dedhia
Rohan-Dedhia force-pushed the fix/8122-v-report-leaks branch from 504a908 to ef82ff1 Compare December 4, 2026 05:14
@echoix

echoix commented Dec 4, 2026

Copy link
Copy Markdown
Member

The code changes look fine.

I don’t see the type of tests like you added here very often. It seems really like it is testing the implementation specifically (by importing the Python code itself, depending on internal details), and a bit less on what the tool does.

What would happen if we refactor just a bit the file, doing the same thing+same output? The tests will probably fail. There’s some testing guidelines in the repo to help you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

module Python Related code is in Python tests Related to Test Suite vector Related to vector data processing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants