Skip to content

Commit 4ecbc7c

Browse files
committed
fix: path is a field again, in step with local_path
Core renamed its path property to resolve_path(), because a property named like a model field wins over the field and makes its value unreadable - osw.express.FileResult declares exactly such a field. With path declared here instead, dict()["path"] and __fields__["path"] work again and the two names always name the same file.
1 parent f199283 commit 4ecbc7c

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

‎src/osw/controller/file/local.py‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import os
99
from pathlib import Path
10-
from typing import IO, Any, Dict
10+
from typing import IO, Any, Dict, Optional
1111

1212
from opensemantic.core.v1 import LocalFileController as _LocalFileController
1313

@@ -17,11 +17,18 @@
1717
class LocalFileController(_LocalFileController):
1818
"""File controller for local files"""
1919

20+
path: Optional[Path] = None
21+
"""Where the content lives, as a Path. A field, not a property: a property
22+
of this name would win over the ``path`` field declared by
23+
``osw.express.FileResult`` and make that field's value unreadable. Kept in
24+
step with the model's own ``local_path`` by the constructor, so either name
25+
reads the same file."""
26+
2027
class Config:
2128
arbitrary_types_allowed = True
2229

2330
def __init__(self, **kwargs):
24-
path = kwargs.pop("path", None)
31+
path = kwargs.get("path")
2532
if path is not None and not kwargs.get("local_path"):
2633
kwargs["local_path"] = str(path)
2734
super().__init__(**kwargs)
@@ -33,6 +40,7 @@ def __init__(self, **kwargs):
3340
raise ValueError(
3441
f"{type(self).__name__} needs a file: pass path= or local_path="
3542
)
43+
self.path = Path(self.local_path)
3644
self._set_metadata()
3745

3846
@classmethod

0 commit comments

Comments
 (0)