Skip to content

Commit c6ad15b

Browse files
authored
Removing surface_header_value validation (#277)
Completes b/453012979 We originally validated that the incoming surface header was either in the form "mcp-<some version number" or "datagemma", to avoid public use of this field that is supposed to only identify data commons surfaces for mixer logs. However, this makes it challenging to change the surface header or introduce new surfaces, and doesn't allow release candidate versions of the MCP server because the version number contains letters. I removed this validation entirely and will instead validate that the surface is an actual DC feature in my usage logs in mixer, where I can loosen validation without releasing a new PyPi package. (also updates version bump because of a previous change)
1 parent bd578ff commit c6ad15b

File tree

5 files changed

+3
-36
lines changed

5 files changed

+3
-36
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## 2.1.2
44

5-
**Date** - 09/23/2025
5+
**Date** - 10/16/2025
66

77
**Release Tag** - [py2.1.2](https://github.com/datacommonsorg/api-python/releases/tag/py2.1.2)
88

datacommons_client/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "2.1.2rc1"
1+
__version__ = "2.1.2"
22
"""
33
Data Commons Client Package
44

datacommons_client/endpoints/base.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import re
22
from typing import Any, Dict, Optional
33

4-
from datacommons_client.utils.error_handling import InvalidSurfaceHeaderValueError
5-
from datacommons_client.utils.error_handling import VALID_SURFACE_HEADER_VALUES
64
from datacommons_client.utils.request_handling import check_instance_is_valid
75
from datacommons_client.utils.request_handling import post_request
86
from datacommons_client.utils.request_handling import resolve_instance_url
@@ -52,15 +50,6 @@ def __init__(
5250
# Resolve from dc_instance
5351
self.base_url = resolve_instance_url(dc_instance)
5452

55-
# if this call originates from another DC product (MCP server, DataGemma, etc.), we indicate that to Mixer
56-
# otherwise, the 'x-surface' header is 'clientlib-python'
57-
if surface_header_value:
58-
# use patterns to support tags like mcp-{VERSION}
59-
if not any(
60-
re.fullmatch(pattern, surface_header_value)
61-
for pattern in VALID_SURFACE_HEADER_VALUES):
62-
raise InvalidSurfaceHeaderValueError
63-
6453
self.headers = self.build_headers(surface_header_value=surface_header_value,
6554
api_key=api_key)
6655

datacommons_client/tests/endpoints/test_base.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
from datacommons_client.endpoints.base import API
66
from datacommons_client.endpoints.base import Endpoint
7-
from datacommons_client.utils.error_handling import InvalidSurfaceHeaderValueError
87

98

109
@patch(
@@ -63,7 +62,7 @@ def test_api_initialization_with_dc_instance(mock_resolve_instance_url):
6362
return_value="https://custom-instance/api/v2",
6463
)
6564
def test_api_initialization_with_surface_header(mock_url):
66-
"""Tests API initialization with an invalid surface header raises an InvalidSurfaceHeaderValueError."""
65+
"""Tests API initialization with a surface header """
6766
api = API(dc_instance="custom-instance", surface_header_value="mcp-1.1.0")
6867
assert api.headers == {
6968
"Content-Type": "application/json",
@@ -77,16 +76,6 @@ def test_api_initialization_invalid_args():
7776
API(dc_instance="custom-instance", url="https://custom.api/v2")
7877

7978

80-
@patch(
81-
"datacommons_client.endpoints.base.resolve_instance_url",
82-
return_value="https://custom-instance/api/v2",
83-
)
84-
def test_api_initialization_invalid_surface(mock_url):
85-
"""Tests API initialization with an invalid surface header raises an InvalidSurfaceHeaderValueError."""
86-
with pytest.raises(InvalidSurfaceHeaderValueError):
87-
API(dc_instance="custom-instance", surface_header_value="not mcp")
88-
89-
9079
@patch(
9180
"datacommons_client.endpoints.base.resolve_instance_url",
9281
return_value="https://custom-instance/api/v2",

datacommons_client/utils/error_handling.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,3 @@ class NoDataForPropertyError(DataCommonsError):
8787
"""Raised when there is no data that meets the specified property filters."""
8888

8989
default_message = "No available data for the specified property filters."
90-
91-
92-
VALID_SURFACE_HEADER_VALUES = ["mcp", r"mcp-[\d\.]+", "datagemma"]
93-
94-
95-
class InvalidSurfaceHeaderValueError(DataCommonsError):
96-
"""
97-
The surface header value must be a surface known to the Data Commons team.
98-
This value is used in the DC usage logs in Mixer.
99-
"""
100-
default_message = "The surface header value should only to indicate a call made from Data Commons surfaces like the MCP server or DataGemma."

0 commit comments

Comments
 (0)