Skip to content

validate_target_id_exists breaks with base URL path prefix #2995

@adamtheturtle

Description

@adamtheturtle

Problem

When using MockVWS with a base_vws_url that includes a path prefix (e.g. http://example.com/prefix), any request to the VWS API fails with UnknownTarget, even for endpoints that have no target ID in their path.

Root cause

validate_target_id_exists in _services_validators/target_validators.py uses the number of path segments to determine whether a target ID is present:

```python
split_path = request_path.split(sep="/")
request_path_no_target_id_length = 2
if len(split_path) == request_path_no_target_id_length:
return
```

For /targets this gives ["", "targets"] → length 2 → returns early (correct).

But with a path prefix the request path is /prefix/targets, which gives ["", "prefix", "targets"] → length 3 → does not return early → split_path[-1] = "targets" is treated as a target ID → UnknownTargetError.

Reproduction

```python
from mock_vws import MockVWS
from mock_vws.database import CloudDatabase
from vws import VWS

base_vws_url = "http://example.com/prefix"
with MockVWS(base_vws_url=base_vws_url) as mock:
database = CloudDatabase()
mock.add_cloud_database(cloud_database=database)
vws_client = VWS(
server_access_key=database.server_access_key,
server_secret_key=database.server_secret_key,
base_vws_url=base_vws_url,
)
vws_client.list_targets() # raises UnknownTargetError: target ID "targets" does not exist
```

Notes

This is analogous to the urljoin routing fix in #2994 / release 2026.02.22.1 — that fixed the routing layer, but the validators still assume no path prefix.

The same pattern likely affects other validators that parse request_path by segment index (e.g. those in key_validators.py, json_validators.py, name_validators.py) depending on what path-structure logic they contain.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions