Skip to content

Commit adeb770

Browse files
authored
Merge branch 'main' into feat/logging
2 parents e682a57 + ece8ccd commit adeb770

12 files changed

Lines changed: 1425 additions & 131 deletions

‎CHANGELOG.md‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,41 @@
1010
1111
<!-- version list -->
1212

13+
## v2.3.2 (2026-09-07)
14+
15+
### Bug Fixes
16+
17+
- **workflow**: Scope _deploy cleanup to what it actually changed
18+
([`4f0593e`](https://github.com/OpenSemanticLab/osw-python/commit/4f0593e47b7a2dd42f304429f2ffb9b5eb5fe47c))
19+
20+
21+
## v2.3.1 (2026-09-03)
22+
23+
### Bug Fixes
24+
25+
- **search**: Keep a limit the caller wrote into the ask query
26+
([`0c75699`](https://github.com/OpenSemanticLab/osw-python/commit/0c756993bcf9a9114c3072ee03037757aaa5fcf5))
27+
28+
- **search**: Treat a SearchParam limit of None as no limit
29+
([`6e94187`](https://github.com/OpenSemanticLab/osw-python/commit/6e94187c455942afdec2746a498c44c6fd5953e0))
30+
31+
32+
## v2.3.0 (2026-09-03)
33+
34+
### Features
35+
36+
- **wtsite**: Parametrize and parallelize modify_search_results
37+
([`d2e2952`](https://github.com/OpenSemanticLab/osw-python/commit/d2e29522033d5f0e8658c318b0fd909406e0f49d))
38+
39+
40+
## v2.2.1 (2026-09-03)
41+
42+
### Bug Fixes
43+
44+
- **core**: Honour per-property settings in the overwrite policy
45+
([`2ed0a1f`](https://github.com/OpenSemanticLab/osw-python/commit/2ed0a1fa027c7b4981a4c5955cbfe9e8d61b9976))
46+
47+
1348
## v2.2.0 (2026-09-02)
1449

1550
### Features

‎CITATION.cff‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ message: "If you use this software, please cite it as below."
33
type: software
44
title: "OpenSemanticWorld Python Package (osw-python)"
55
# Managed by python-semantic-release (version_variables). Do not edit by hand.
6-
version: 2.2.0
6+
version: 2.3.2
77
abstract: "Python toolset for data processing, queries, wikicode generation and page manipulation within OpenSemanticLab: work with OpenSemanticLab instances as typed pydantic entities, query with semantic search, generate models from wiki schemas, and write changes back."
88
repository-code: "https://github.com/OpenSemanticLab/osw-python"
99
url: "https://opensemanticlab.github.io/osw-python/"

‎pyproject.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ license-files = ["LICENSE.txt"]
88
requires-python = ">=3.10,<3.14"
99
# Managed by python-semantic-release (see [tool.semantic_release]). Do not
1010
# edit by hand; it is bumped automatically on merge to main.
11-
version = "2.2.0"
11+
version = "2.3.2"
1212
classifiers = [
1313
"Development Status :: 3 - Alpha",
1414
"Intended Audience :: Developers",

‎src/osw/core.py‎

Lines changed: 69 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,7 +1337,13 @@ class OverwriteClassParam(OswBaseModel):
13371337

13381338
@validator("per_property")
13391339
def validate_per_property(cls, per_property, values):
1340+
if per_property is None: # nothing to check, the fallback applies
1341+
return per_property
13401342
model_ = values.get("model")
1343+
if model_ is None:
1344+
# 'model' itself did not validate; without it the property names
1345+
# below cannot be checked at all
1346+
raise ValueError("'model' is required to validate 'per_property'")
13411347
field_names = list(model_.__fields__.keys())
13421348
keys = per_property.keys()
13431349
if not all(key in field_names for key in keys):
@@ -1348,36 +1354,68 @@ def validate_per_property(cls, per_property, values):
13481354

13491355
return per_property
13501356

1357+
@classmethod
1358+
def _normalize_overwrite(cls, value):
1359+
"""Replace the two non-policy values by the default setting.
1360+
1361+
Neither ``None`` nor the ``none`` sentinel is a policy:
1362+
``get_overwrite_setting()`` would hand them to the merge, where they
1363+
match no branch and silently behave like 'false'.
1364+
"""
1365+
if value is None or value is AddOverwriteClassOptions.none:
1366+
return cls.__fields__["overwrite"].get_default()
1367+
return value
1368+
13511369
def __setattr__(self, key, value):
13521370
"""Called when setting an attribute"""
1371+
if key == "overwrite":
1372+
value = self._normalize_overwrite(value)
1373+
# the effective settings are derived from these three, so any of them
1374+
# changing has to rebuild them
1375+
if key not in ("model", "overwrite", "per_property"):
1376+
super().__setattr__(key, value)
1377+
return
1378+
previous = getattr(self, key)
13531379
super().__setattr__(key, value)
1354-
if key == "per_property":
1355-
# compare value and self.per_property
1356-
if value != self.per_property and value is not None:
1357-
self._per_property = {
1358-
field_name: value.get(field_name, self.overwrite)
1359-
for field_name in self.model.__fields__.keys()
1360-
}
1361-
elif key == "overwrite" or key == "model":
1362-
if self.per_property is not None:
1363-
self._per_property = {
1364-
field_name: self.per_property.get(field_name, self.overwrite)
1365-
for field_name in self.model.__fields__.keys()
1366-
}
1380+
try:
1381+
self._sync_per_property()
1382+
except ValueError:
1383+
# _sync_per_property() rejects before it touches _per_property,
1384+
# so restoring the field is enough to undo the assignment. Leaving
1385+
# a rejected value in place would let it take effect later, on the
1386+
# next assignment that happens to be accepted.
1387+
super().__setattr__(key, previous)
1388+
raise
13671389

13681390
def __init__(self, **data):
13691391
"""Called after validation. Sets the fallback for every property that
13701392
has not been specified in per_property."""
13711393
super().__init__(**data)
1372-
per_property_ = {}
1373-
if self.per_property is not None:
1374-
per_property_ = self.per_property
1394+
# routed through __setattr__, which normalizes and rebuilds
1395+
self.overwrite = self.overwrite
1396+
# todo: from class definition get properties with hidden /
1397+
# read_only option # those can be safely overwritten - set the to True
1398+
1399+
def _sync_per_property(self) -> None:
1400+
"""Rebuild the effective overwrite setting of every model field."""
1401+
if self.per_property and isinstance(
1402+
self.overwrite, AddOverwriteClassOptions
1403+
):
1404+
# _apply_overwrite_policy() short-circuits on 'replace remote'
1405+
# and 'keep existing' before it looks at a single property, so
1406+
# this combination would discard 'per_property' silently. Check
1407+
# it here rather than in a validator so that it also holds when
1408+
# either field is reassigned after construction.
1409+
raise ValueError(
1410+
f"'per_property' cannot be combined with overwrite="
1411+
f"'{self.overwrite.value}', which acts on the entity as a "
1412+
f"whole. Use an OverwriteOptions value for 'overwrite'."
1413+
)
1414+
per_property_ = self.per_property or {}
13751415
self._per_property = {
13761416
field_name: per_property_.get(field_name, self.overwrite)
13771417
for field_name in self.model.__fields__.keys()
13781418
}
1379-
# todo: from class definition get properties with hidden /
1380-
# read_only option # those can be safely overwritten - set the to True
13811419

13821420
def get_overwrite_setting(self, property_name: str) -> OverwriteOptions:
13831421
"""Returns the fallback overwrite option for the given field name"""
@@ -1773,7 +1811,18 @@ def store_entity_(
17731811
offline=param.offline,
17741812
)
17751813
)
1776-
if len(meta_category_templates.keys()) > 0:
1814+
# _apply_overwrite_policy() returned the remote page untouched. The
1815+
# schema regeneration below writes the jsonschema slot regardless of
1816+
# the policy, which would edit a page the caller asked to keep.
1817+
kept_existing = (
1818+
page.exists
1819+
# mirrors the branch order of _apply_overwrite_policy(), which
1820+
# tests 'offline is True' before it tests 'keep existing'
1821+
and param.offline is not True
1822+
and overwrite_class_param.overwrite
1823+
== AddOverwriteClassOptions.keep_existing
1824+
)
1825+
if not kept_existing and len(meta_category_templates.keys()) > 0:
17771826
generated_schemas = {}
17781827
try:
17791828
jsondata = page.get_slot_content("jsondata")
@@ -1812,7 +1861,7 @@ def store_entity_(
18121861
)
18131862
).aggregated_schema
18141863
page.set_slot_content("jsonschema", new_schema)
1815-
if param.offline is False:
1864+
if param.offline is False and not kept_existing:
18161865
page.edit(
18171866
param.edit_comment, bot_edit=param.bot_edit
18181867
) # will set page.changed if the content of the page has changed

‎src/osw/utils/workflow.py‎

Lines changed: 63 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -667,75 +667,78 @@ async def _deploy(param: DeployParam):
667667

668668
_original_api_url = None
669669
_original_httpx_init = None
670+
_api_url_overridden = False
670671
gateway_url = param.public_url or environ.get("PREFECT_API_URL", "")
671-
if _is_apigateway_url(gateway_url) and param.osw is not None:
672-
_original_api_url = environ.get("PREFECT_API_URL")
673-
environ["PREFECT_API_URL"] = gateway_url
674-
_mw_site = param.osw.site.mw_site
675-
676-
def _relogin():
677-
cred = param.osw.site._cred_mngr.get_credential(param.osw.site._iri)
678-
_mw_site.login(username=cred.username, password=cred.password)
679-
680-
_gw_transport = ApiGatewayTransport(
681-
gateway_url=gateway_url,
682-
mw_site=_mw_site,
683-
relogin_cb=_relogin,
684-
)
685-
# Patch httpx.AsyncClient to auto-inject our transport when
686-
# the base_url is an ApiGateway URL. One patch covers ALL
687-
# Prefect client instances regardless of how they're created.
688-
_original_httpx_init = httpx.AsyncClient.__init__
689-
690-
def _patched_httpx_init(self, *args, **kwargs):
691-
base = str(kwargs.get("base_url", ""))
692-
if _is_apigateway_url(base) and "transport" not in kwargs:
693-
kwargs["transport"] = _gw_transport
694-
_original_httpx_init(self, *args, **kwargs)
695-
696-
httpx.AsyncClient.__init__ = _patched_httpx_init
697-
698-
# Auto-install .pth hook so Prefect subprocesses also get patched
699-
_pth_target = os.path.join(_get_site_packages(), _PTH_FILENAME)
700-
if not os.path.exists(_pth_target):
701-
install_gateway_hook()
702-
703-
deployments = []
704-
705-
for deploy_config in param.deployments:
706-
flow: Flow = deploy_config.flow
707-
# Set deployment name if not provided
708-
if deploy_config.name is None or deploy_config.name == "":
709-
deploy_config.name = flow.name + "-deployment"
710-
711-
# Match valid args of flow.to_deployment and deploy_config
712-
kwargs = match_func_model_args(func=flow.to_deployment, model=deploy_config)
713-
# Set config via matching flow.to_deployment arguments
714-
config = await flow.to_deployment(**kwargs)
715-
await config.apply() # returns the deployment_uuid
716-
717-
deployments.append(config)
718-
719-
# Register flow on OSW if an instance is provided
720-
if param.osw is not None:
721-
await register_flow(
722-
osw_instance=param.osw,
723-
flow=flow,
724-
namespace_uuid=param.namespace_uuid,
725-
public_url=param.public_url,
672+
try:
673+
if _is_apigateway_url(gateway_url) and param.osw is not None:
674+
_original_api_url = environ.get("PREFECT_API_URL")
675+
environ["PREFECT_API_URL"] = gateway_url
676+
_api_url_overridden = True
677+
_mw_site = param.osw.site.mw_site
678+
679+
def _relogin():
680+
cred = param.osw.site._cred_mngr.get_credential(param.osw.site._iri)
681+
_mw_site.login(username=cred.username, password=cred.password)
682+
683+
_gw_transport = ApiGatewayTransport(
684+
gateway_url=gateway_url,
685+
mw_site=_mw_site,
686+
relogin_cb=_relogin,
726687
)
688+
# Patch httpx.AsyncClient to auto-inject our transport when
689+
# the base_url is an ApiGateway URL. One patch covers ALL
690+
# Prefect client instances regardless of how they're created.
691+
_original_httpx_init = httpx.AsyncClient.__init__
692+
693+
def _patched_httpx_init(self, *args, **kwargs):
694+
base = str(kwargs.get("base_url", ""))
695+
if _is_apigateway_url(base) and "transport" not in kwargs:
696+
kwargs["transport"] = _gw_transport
697+
_original_httpx_init(self, *args, **kwargs)
698+
699+
httpx.AsyncClient.__init__ = _patched_httpx_init
700+
701+
# Auto-install .pth hook so Prefect subprocesses also get patched
702+
_pth_target = os.path.join(_get_site_packages(), _PTH_FILENAME)
703+
if not os.path.exists(_pth_target):
704+
install_gateway_hook()
705+
706+
deployments = []
707+
708+
for deploy_config in param.deployments:
709+
flow: Flow = deploy_config.flow
710+
# Set deployment name if not provided
711+
if deploy_config.name is None or deploy_config.name == "":
712+
deploy_config.name = flow.name + "-deployment"
713+
714+
# Match valid args of flow.to_deployment and deploy_config
715+
kwargs = match_func_model_args(func=flow.to_deployment, model=deploy_config)
716+
# Set config via matching flow.to_deployment arguments
717+
config = await flow.to_deployment(**kwargs)
718+
await config.apply() # returns the deployment_uuid
719+
720+
deployments.append(config)
721+
722+
# Register flow on OSW if an instance is provided
723+
if param.osw is not None:
724+
await register_flow(
725+
osw_instance=param.osw,
726+
flow=flow,
727+
namespace_uuid=param.namespace_uuid,
728+
public_url=param.public_url,
729+
)
727730

728-
try:
729731
await serve(*deployments)
730732
finally:
731733
# Restore patched httpx.AsyncClient.__init__
732734
if _original_httpx_init is not None:
733735
httpx.AsyncClient.__init__ = _original_httpx_init
734736
# Restore original PREFECT_API_URL if we overrode it
735-
if _original_api_url is not None:
736-
environ["PREFECT_API_URL"] = _original_api_url
737-
elif _is_apigateway_url(gateway_url):
738-
environ.pop("PREFECT_API_URL", None)
737+
if _api_url_overridden:
738+
if _original_api_url is not None:
739+
environ["PREFECT_API_URL"] = _original_api_url
740+
else:
741+
environ.pop("PREFECT_API_URL", None)
739742

740743

741744
def deploy(param: DeployParam):

0 commit comments

Comments
 (0)