Spaces:
Running
Running
fix: reject invalid metric text
Browse files- ingest.py +2 -0
- test_ingest.py +12 -0
ingest.py
CHANGED
|
@@ -52,6 +52,7 @@ def _config(value):
|
|
| 52 |
raise ValueError(
|
| 53 |
"config string values must have at most 512 characters"
|
| 54 |
)
|
|
|
|
| 55 |
elif not _number(item) or item < 0:
|
| 56 |
raise ValueError("config counts must be finite nonnegative numbers")
|
| 57 |
return value or None
|
|
@@ -86,6 +87,7 @@ def validate(payload):
|
|
| 86 |
for key, value in metrics.items():
|
| 87 |
if not isinstance(key, str) or not 1 <= len(key) <= 128:
|
| 88 |
raise ValueError("metric names must contain 1 to 128 characters")
|
|
|
|
| 89 |
if not _number(value):
|
| 90 |
raise ValueError("metrics must contain only finite numbers")
|
| 91 |
entry_config = _config(entry.get("config"))
|
|
|
|
| 52 |
raise ValueError(
|
| 53 |
"config string values must have at most 512 characters"
|
| 54 |
)
|
| 55 |
+
item.encode("utf-8")
|
| 56 |
elif not _number(item) or item < 0:
|
| 57 |
raise ValueError("config counts must be finite nonnegative numbers")
|
| 58 |
return value or None
|
|
|
|
| 87 |
for key, value in metrics.items():
|
| 88 |
if not isinstance(key, str) or not 1 <= len(key) <= 128:
|
| 89 |
raise ValueError("metric names must contain 1 to 128 characters")
|
| 90 |
+
key.encode("utf-8")
|
| 91 |
if not _number(value):
|
| 92 |
raise ValueError("metrics must contain only finite numbers")
|
| 93 |
entry_config = _config(entry.get("config"))
|
test_ingest.py
CHANGED
|
@@ -97,6 +97,18 @@ def test_nonfinite_and_oversized_payload_rejected(client):
|
|
| 97 |
)
|
| 98 |
|
| 99 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
def test_retry_is_idempotent_and_cannot_overwrite_metric(client):
|
| 101 |
from trackio.sqlite_storage import SQLiteStorage
|
| 102 |
|
|
|
|
| 97 |
)
|
| 98 |
|
| 99 |
|
| 100 |
+
@pytest.mark.parametrize(
|
| 101 |
+
"updates",
|
| 102 |
+
[
|
| 103 |
+
{"metrics": {"\ud800": 0.2}},
|
| 104 |
+
{"config": {"model": "\ud800"}},
|
| 105 |
+
],
|
| 106 |
+
)
|
| 107 |
+
def test_unpaired_surrogates_rejected(client, updates):
|
| 108 |
+
response = client.post("/ingest", content=json.dumps(batch(**updates)))
|
| 109 |
+
assert response.status_code == 400
|
| 110 |
+
|
| 111 |
+
|
| 112 |
def test_retry_is_idempotent_and_cannot_overwrite_metric(client):
|
| 113 |
from trackio.sqlite_storage import SQLiteStorage
|
| 114 |
|