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

Cannot overwrite model #1830

Closed
visr opened this issue Sep 19, 2024 · 1 comment
Closed

Cannot overwrite model #1830

visr opened this issue Sep 19, 2024 · 1 comment
Labels
bug Indicates an unexpected problem or unintended behavior python Relates to one of the Ribasim python packages v1.0 Release!

Comments

@visr
Copy link
Member

visr commented Sep 19, 2024

This used to work:

import ribasim

toml_path = r"generated_testmodels\basic\ribasim.toml"
model = ribasim.Model.read(toml_path)
model.write(toml_path)
PermissionError                           Traceback (most recent call last)
File d:\repo\ribasim\Ribasim\models\see.py:1
----> 1 model.write(toml_path)

File D:\repo\ribasim\Ribasim\python\ribasim\ribasim\model.py:302, in Model.write(self, filepath)
    300 directory = filepath.parent
    301 directory.mkdir(parents=True, exist_ok=True)
--> 302 self._save(directory, self.input_dir)
    303 fn = self._write_toml(filepath)
    305 context_file_writing.set({})

File D:\repo\ribasim\Ribasim\python\ribasim\ribasim\model.py:194, in Model._save(self, directory, input_dir)
    192 db_path = directory / input_dir / "database.gpkg"
    193 db_path.parent.mkdir(parents=True, exist_ok=True)
--> 194 db_path.unlink(missing_ok=True)
    195 context_file_writing.get()["database"] = db_path
    197 self.edge._save(directory, input_dir)

File d:\repo\ribasim\Ribasim\.pixi\envs\dev\Lib\pathlib.py:1342, in Path.unlink(self, missing_ok)
   1337 """
   1338 Remove this file or link.
   1339 If the path is a directory, use rmdir() instead.
   1340 """
   1341 try:
-> 1342     os.unlink(self)
   1343 except FileNotFoundError:
   1344     if not missing_ok:

PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'd:\\repo\\ribasim\\Ribasim\\generated_testmodels\\basic\\database.gpkg'

I haven't verified but I suspect this relates to the migrations PR #1764 which changed around how contextlib is used.

@visr visr added python Relates to one of the Ribasim python packages bug Indicates an unexpected problem or unintended behavior v1.0 Release! labels Sep 19, 2024
visr added a commit that referenced this issue Sep 23, 2024
Working on #1830, it seemed like this was missing a closing. This makes
it more in line with db_utils.py.

It doesn't seem to be enough to fix that issue though.

---------

Co-authored-by: Maarten Pronk <[email protected]>
@visr
Copy link
Member Author

visr commented Sep 23, 2024

Fixed by #1831.

@visr visr closed this as completed Sep 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior python Relates to one of the Ribasim python packages v1.0 Release!
Projects
Status: Done
Development

No branches or pull requests

1 participant