Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/accept-unknown-enum-values.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@fingerprint/python-sdk': patch
---
Comment thread
erayaydin marked this conversation as resolved.

Accept unknown enum values gracefully instead of throwing errors during deserialization
18 changes: 1 addition & 17 deletions fingerprint_server_sdk/models/bot_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import re # noqa: F401
from typing import Any, ClassVar, Optional

from pydantic import BaseModel, ConfigDict, Field, StrictStr, field_validator
from pydantic import BaseModel, ConfigDict, Field, StrictStr
from typing_extensions import Self


Expand Down Expand Up @@ -45,22 +45,6 @@ class BotInfo(BaseModel):
'confidence',
]

@field_validator('identity')
def identity_validate_enum(cls, value: Any) -> Any:
"""Validates the enum"""
if value not in set(['verified', 'signed', 'spoofed', 'unknown']):
raise ValueError(
"must be one of enum values ('verified', 'signed', 'spoofed', 'unknown')"
)
return value

@field_validator('confidence')
def confidence_validate_enum(cls, value: Any) -> Any:
"""Validates the enum"""
if value not in set(['low', 'medium', 'high']):
raise ValueError("must be one of enum values ('low', 'medium', 'high')")
return value

model_config = ConfigDict(
populate_by_name=True,
validate_assignment=True,
Expand Down
12 changes: 12 additions & 0 deletions fingerprint_server_sdk/models/bot_info_category.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,15 @@ class BotInfoCategory(str, Enum):
def from_json(cls, json_str: str) -> Self:
"""Create an instance of BotInfoCategory from a JSON string"""
return cls(json.loads(json_str))

@classmethod
def _missing_(cls, value: object) -> Self:
"""Accept unknown enum values gracefully."""
if not isinstance(value, str):
raise ValueError(f'{value!r} is not a valid {cls.__name__}')
obj = str.__new__(cls, value)
obj._name_ = str(value)
obj._value_ = value
# cache it so the same value won't trigger `_missing_` again
cls._value2member_map_[value] = obj
return obj
12 changes: 12 additions & 0 deletions fingerprint_server_sdk/models/bot_info_confidence.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,15 @@ class BotInfoConfidence(str, Enum):
def from_json(cls, json_str: str) -> Self:
"""Create an instance of BotInfoConfidence from a JSON string"""
return cls(json.loads(json_str))

@classmethod
def _missing_(cls, value: object) -> Self:
"""Accept unknown enum values gracefully."""
if not isinstance(value, str):
raise ValueError(f'{value!r} is not a valid {cls.__name__}')
obj = str.__new__(cls, value)
obj._name_ = str(value)
obj._value_ = value
# cache it so the same value won't trigger `_missing_` again
cls._value2member_map_[value] = obj
return obj
12 changes: 12 additions & 0 deletions fingerprint_server_sdk/models/bot_info_identity.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,15 @@ class BotInfoIdentity(str, Enum):
def from_json(cls, json_str: str) -> Self:
"""Create an instance of BotInfoIdentity from a JSON string"""
return cls(json.loads(json_str))

@classmethod
def _missing_(cls, value: object) -> Self:
"""Accept unknown enum values gracefully."""
if not isinstance(value, str):
raise ValueError(f'{value!r} is not a valid {cls.__name__}')
obj = str.__new__(cls, value)
obj._name_ = str(value)
obj._value_ = value
# cache it so the same value won't trigger `_missing_` again
cls._value2member_map_[value] = obj
return obj
12 changes: 12 additions & 0 deletions fingerprint_server_sdk/models/bot_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,15 @@ class BotResult(str, Enum):
def from_json(cls, json_str: str) -> Self:
"""Create an instance of BotResult from a JSON string"""
return cls(json.loads(json_str))

@classmethod
def _missing_(cls, value: object) -> Self:
"""Accept unknown enum values gracefully."""
if not isinstance(value, str):
raise ValueError(f'{value!r} is not a valid {cls.__name__}')
obj = str.__new__(cls, value)
obj._name_ = str(value)
obj._value_ = value
# cache it so the same value won't trigger `_missing_` again
cls._value2member_map_[value] = obj
return obj
12 changes: 12 additions & 0 deletions fingerprint_server_sdk/models/error_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,15 @@ class ErrorCode(str, Enum):
def from_json(cls, json_str: str) -> Self:
"""Create an instance of ErrorCode from a JSON string"""
return cls(json.loads(json_str))

@classmethod
def _missing_(cls, value: object) -> Self:
"""Accept unknown enum values gracefully."""
if not isinstance(value, str):
raise ValueError(f'{value!r} is not a valid {cls.__name__}')
obj = str.__new__(cls, value)
obj._name_ = str(value)
obj._value_ = value
# cache it so the same value won't trigger `_missing_` again
cls._value2member_map_[value] = obj
return obj
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,15 @@ class IncrementalIdentificationStatus(str, Enum):
def from_json(cls, json_str: str) -> Self:
"""Create an instance of IncrementalIdentificationStatus from a JSON string"""
return cls(json.loads(json_str))

@classmethod
def _missing_(cls, value: object) -> Self:
"""Accept unknown enum values gracefully."""
if not isinstance(value, str):
raise ValueError(f'{value!r} is not a valid {cls.__name__}')
obj = str.__new__(cls, value)
obj._name_ = str(value)
obj._value_ = value
# cache it so the same value won't trigger `_missing_` again
cls._value2member_map_[value] = obj
return obj
11 changes: 1 addition & 10 deletions fingerprint_server_sdk/models/proximity.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import re # noqa: F401
from typing import Annotated, Any, ClassVar, Optional, Union

from pydantic import BaseModel, ConfigDict, Field, StrictInt, StrictStr, field_validator
from pydantic import BaseModel, ConfigDict, Field, StrictInt, StrictStr
from typing_extensions import Self


Expand All @@ -40,15 +40,6 @@ class Proximity(BaseModel):
)
__properties: ClassVar[list[str]] = ['id', 'precision_radius', 'confidence']

@field_validator('precision_radius')
def precision_radius_validate_enum(cls, value: Any) -> Any:
"""Validates the enum"""
if value not in set([10, 25, 65, 175, 450, 1200, 3300, 8500, 22500]):
raise ValueError(
'must be one of enum values (10, 25, 65, 175, 450, 1200, 3300, 8500, 22500)'
)
return value

model_config = ConfigDict(
populate_by_name=True,
validate_assignment=True,
Expand Down
12 changes: 12 additions & 0 deletions fingerprint_server_sdk/models/proxy_confidence.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,15 @@ class ProxyConfidence(str, Enum):
def from_json(cls, json_str: str) -> Self:
"""Create an instance of ProxyConfidence from a JSON string"""
return cls(json.loads(json_str))

@classmethod
def _missing_(cls, value: object) -> Self:
"""Accept unknown enum values gracefully."""
if not isinstance(value, str):
raise ValueError(f'{value!r} is not a valid {cls.__name__}')
obj = str.__new__(cls, value)
obj._name_ = str(value)
obj._value_ = value
# cache it so the same value won't trigger `_missing_` again
cls._value2member_map_[value] = obj
return obj
9 changes: 1 addition & 8 deletions fingerprint_server_sdk/models/proxy_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import re # noqa: F401
from typing import Any, ClassVar, Optional

from pydantic import BaseModel, ConfigDict, Field, StrictInt, StrictStr, field_validator
from pydantic import BaseModel, ConfigDict, Field, StrictInt, StrictStr
from typing_extensions import Self


Expand All @@ -39,13 +39,6 @@ class ProxyDetails(BaseModel):
)
__properties: ClassVar[list[str]] = ['proxy_type', 'last_seen_at', 'provider']

@field_validator('proxy_type')
def proxy_type_validate_enum(cls, value: Any) -> Any:
"""Validates the enum"""
if value not in set(['residential', 'data_center']):
raise ValueError("must be one of enum values ('residential', 'data_center')")
return value

model_config = ConfigDict(
populate_by_name=True,
validate_assignment=True,
Expand Down
12 changes: 12 additions & 0 deletions fingerprint_server_sdk/models/rare_device_percentile_bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,15 @@ class RareDevicePercentileBucket(str, Enum):
def from_json(cls, json_str: str) -> Self:
"""Create an instance of RareDevicePercentileBucket from a JSON string"""
return cls(json.loads(json_str))

@classmethod
def _missing_(cls, value: object) -> Self:
"""Accept unknown enum values gracefully."""
if not isinstance(value, str):
raise ValueError(f'{value!r} is not a valid {cls.__name__}')
obj = str.__new__(cls, value)
obj._name_ = str(value)
obj._value_ = value
# cache it so the same value won't trigger `_missing_` again
cls._value2member_map_[value] = obj
return obj
12 changes: 12 additions & 0 deletions fingerprint_server_sdk/models/rule_action_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,15 @@ class RuleActionType(str, Enum):
def from_json(cls, json_str: str) -> Self:
"""Create an instance of RuleActionType from a JSON string"""
return cls(json.loads(json_str))

@classmethod
def _missing_(cls, value: object) -> Self:
"""Accept unknown enum values gracefully."""
if not isinstance(value, str):
raise ValueError(f'{value!r} is not a valid {cls.__name__}')
obj = str.__new__(cls, value)
obj._name_ = str(value)
obj._value_ = value
# cache it so the same value won't trigger `_missing_` again
cls._value2member_map_[value] = obj
return obj
9 changes: 1 addition & 8 deletions fingerprint_server_sdk/models/sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import re # noqa: F401
from typing import Any, ClassVar, Optional

from pydantic import BaseModel, ConfigDict, Field, StrictStr, field_validator
from pydantic import BaseModel, ConfigDict, Field, StrictStr
from typing_extensions import Self

from fingerprint_server_sdk.models.integration import Integration
Expand All @@ -37,13 +37,6 @@ class SDK(BaseModel):
integrations: Optional[list[Integration]] = None
__properties: ClassVar[list[str]] = ['platform', 'version', 'integrations']

@field_validator('platform')
def platform_validate_enum(cls, value: Any) -> Any:
"""Validates the enum"""
if value not in set(['js', 'android', 'ios', 'unknown']):
raise ValueError("must be one of enum values ('js', 'android', 'ios', 'unknown')")
return value

model_config = ConfigDict(
populate_by_name=True,
validate_assignment=True,
Expand Down
12 changes: 12 additions & 0 deletions fingerprint_server_sdk/models/search_events_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,15 @@ class SearchEventsBot(str, Enum):
def from_json(cls, json_str: str) -> Self:
"""Create an instance of SearchEventsBot from a JSON string"""
return cls(json.loads(json_str))

@classmethod
def _missing_(cls, value: object) -> Self:
"""Accept unknown enum values gracefully."""
if not isinstance(value, str):
raise ValueError(f'{value!r} is not a valid {cls.__name__}')
obj = str.__new__(cls, value)
obj._name_ = str(value)
obj._value_ = value
# cache it so the same value won't trigger `_missing_` again
cls._value2member_map_[value] = obj
return obj
12 changes: 12 additions & 0 deletions fingerprint_server_sdk/models/search_events_bot_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,15 @@ class SearchEventsBotInfo(str, Enum):
def from_json(cls, json_str: str) -> Self:
"""Create an instance of SearchEventsBotInfo from a JSON string"""
return cls(json.loads(json_str))

@classmethod
def _missing_(cls, value: object) -> Self:
"""Accept unknown enum values gracefully."""
if not isinstance(value, str):
raise ValueError(f'{value!r} is not a valid {cls.__name__}')
obj = str.__new__(cls, value)
obj._name_ = str(value)
obj._value_ = value
# cache it so the same value won't trigger `_missing_` again
cls._value2member_map_[value] = obj
return obj
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,15 @@ class SearchEventsIncrementalIdentificationStatus(str, Enum):
def from_json(cls, json_str: str) -> Self:
"""Create an instance of SearchEventsIncrementalIdentificationStatus from a JSON string"""
return cls(json.loads(json_str))

@classmethod
def _missing_(cls, value: object) -> Self:
"""Accept unknown enum values gracefully."""
if not isinstance(value, str):
raise ValueError(f'{value!r} is not a valid {cls.__name__}')
obj = str.__new__(cls, value)
obj._name_ = str(value)
obj._value_ = value
# cache it so the same value won't trigger `_missing_` again
cls._value2member_map_[value] = obj
return obj
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,15 @@ class SearchEventsRareDevicePercentileBucket(str, Enum):
def from_json(cls, json_str: str) -> Self:
"""Create an instance of SearchEventsRareDevicePercentileBucket from a JSON string"""
return cls(json.loads(json_str))

@classmethod
def _missing_(cls, value: object) -> Self:
"""Accept unknown enum values gracefully."""
if not isinstance(value, str):
raise ValueError(f'{value!r} is not a valid {cls.__name__}')
obj = str.__new__(cls, value)
obj._name_ = str(value)
obj._value_ = value
# cache it so the same value won't trigger `_missing_` again
cls._value2member_map_[value] = obj
return obj
12 changes: 12 additions & 0 deletions fingerprint_server_sdk/models/search_events_sdk_platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,15 @@ class SearchEventsSdkPlatform(str, Enum):
def from_json(cls, json_str: str) -> Self:
"""Create an instance of SearchEventsSdkPlatform from a JSON string"""
return cls(json.loads(json_str))

@classmethod
def _missing_(cls, value: object) -> Self:
"""Accept unknown enum values gracefully."""
if not isinstance(value, str):
raise ValueError(f'{value!r} is not a valid {cls.__name__}')
obj = str.__new__(cls, value)
obj._name_ = str(value)
obj._value_ = value
# cache it so the same value won't trigger `_missing_` again
cls._value2member_map_[value] = obj
return obj
12 changes: 12 additions & 0 deletions fingerprint_server_sdk/models/search_events_vpn_confidence.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,15 @@ class SearchEventsVpnConfidence(str, Enum):
def from_json(cls, json_str: str) -> Self:
"""Create an instance of SearchEventsVpnConfidence from a JSON string"""
return cls(json.loads(json_str))

@classmethod
def _missing_(cls, value: object) -> Self:
"""Accept unknown enum values gracefully."""
if not isinstance(value, str):
raise ValueError(f'{value!r} is not a valid {cls.__name__}')
obj = str.__new__(cls, value)
obj._name_ = str(value)
obj._value_ = value
# cache it so the same value won't trigger `_missing_` again
cls._value2member_map_[value] = obj
return obj
12 changes: 12 additions & 0 deletions fingerprint_server_sdk/models/tampering_confidence.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,15 @@ class TamperingConfidence(str, Enum):
def from_json(cls, json_str: str) -> Self:
"""Create an instance of TamperingConfidence from a JSON string"""
return cls(json.loads(json_str))

@classmethod
def _missing_(cls, value: object) -> Self:
"""Accept unknown enum values gracefully."""
if not isinstance(value, str):
raise ValueError(f'{value!r} is not a valid {cls.__name__}')
obj = str.__new__(cls, value)
obj._name_ = str(value)
obj._value_ = value
# cache it so the same value won't trigger `_missing_` again
cls._value2member_map_[value] = obj
return obj
12 changes: 12 additions & 0 deletions fingerprint_server_sdk/models/vpn_confidence.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,15 @@ class VpnConfidence(str, Enum):
def from_json(cls, json_str: str) -> Self:
"""Create an instance of VpnConfidence from a JSON string"""
return cls(json.loads(json_str))

@classmethod
def _missing_(cls, value: object) -> Self:
"""Accept unknown enum values gracefully."""
if not isinstance(value, str):
raise ValueError(f'{value!r} is not a valid {cls.__name__}')
obj = str.__new__(cls, value)
obj._name_ = str(value)
obj._value_ = value
# cache it so the same value won't trigger `_missing_` again
cls._value2member_map_[value] = obj
return obj
Loading
Loading