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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## [Unreleased](https://github.com/openfga/python-sdk/compare/v0.8.1...HEAD)

- feat: remove client-side validation - thanks @GMorris-professional (#155)
- fix: change default max retry limit to 3 from 15 - thanks @ovindu-a (#155)

## v0.8.1

### [0.8.1](https://github.com/openfga/python-sdk/compare/v0.8.0...v0.8.1) (2024-11-26)
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ import openfga_sdk

We strongly recommend you initialize the `OpenFgaClient` only once and then re-use it throughout your app, otherwise you will incur the cost of having to re-initialize multiple times or at every request, the cost of reduced connection pooling and re-use, and would be particularly costly in the client credentials flow, as that flow will be preformed on every request.

> The `OpenFgaClient` will by default retry API requests up to 15 times on 429 and 5xx errors.
> The `OpenFgaClient` will by default retry API requests up to 3 times on 429 and 5xx errors.

#### No Credentials

Expand Down Expand Up @@ -720,7 +720,7 @@ response = await fga_client.check(body, options)
##### Batch Check

Run a set of [checks](#check). Batch Check will return `allowed: false` if it encounters an error, and will return the error in the body.
If 429s or 5xxs are encountered, the underlying check will retry up to 15 times before giving up.
If 429s or 5xxs are encountered, the underlying check will retry up to 3 times before giving up.

```python
# from openfga_sdk import OpenFgaClient
Expand Down Expand Up @@ -1015,7 +1015,7 @@ response = await fga_client.write_assertions(body, options)

### Retries

If a network request fails with a 429 or 5xx error from the server, the SDK will automatically retry the request up to 15 times with a minimum wait time of 100 milliseconds between each attempt.
If a network request fails with a 429 or 5xx error from the server, the SDK will automatically retry the request up to 3 times with a minimum wait time of 100 milliseconds between each attempt.

To customize this behavior, create a `RetryParams` object and assign values to the `max_retry` and `min_wait_in_ms` constructor parameters. `max_retry` determines the maximum number of retries (up to 15), while `min_wait_in_ms` sets the minimum wait time between retries in milliseconds.

Expand Down
47 changes: 1 addition & 46 deletions openfga_sdk/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,6 @@
from openfga_sdk.telemetry.histograms import TelemetryHistogram
from openfga_sdk.validation import is_well_formed_ulid_string

JSON_SCHEMA_VALIDATION_KEYWORDS = {
"multipleOf",
"maximum",
"exclusiveMaximum",
"minimum",
"exclusiveMinimum",
"maxLength",
"minLength",
"pattern",
"maxItems",
"minItems",
}


class RetryParams:
"""NOTE: This class is auto generated by OpenAPI Generator
Expand All @@ -56,7 +43,7 @@ class RetryParams:
:param min_wait_in_ms: Minimum wait (in ms) between retry
"""

def __init__(self, max_retry=15, min_wait_in_ms=100):
def __init__(self, max_retry=3, min_wait_in_ms=100):
self._max_retry = max_retry
self._min_wait_in_ms = min_wait_in_ms

Expand Down Expand Up @@ -144,19 +131,6 @@ class Configuration:
then all undeclared properties received by the server are injected into the
additional properties map. In that case, there are undeclared properties, and
nothing to discard.
:param disabled_client_side_validations (string): Comma-separated list of
JSON schema validation keywords to disable JSON schema structural validation
rules. The following keywords may be specified: multipleOf, maximum,
exclusiveMaximum, minimum, exclusiveMinimum, maxLength, minLength, pattern,
maxItems, minItems.
By default, the validation is performed for data generated locally by the client
and data received from the server, independent of any validation performed by
the server side. If the input data does not satisfy the JSON schema validation
rules specified in the OpenAPI document, an exception is raised.
If disabled_client_side_validations is set, structural validation is
disabled. This can be useful to troubleshoot data validation problem, such as
when the OpenAPI document validation rules do not match the actual API data
received by the server.
:param server_index: Index to servers configuration.
:param server_variables: Mapping with string values to replace variables in
templated server configuration. The validation of enums is performed for
Expand Down Expand Up @@ -186,7 +160,6 @@ def __init__(
username=None,
password=None,
discard_unknown_keys=False,
disabled_client_side_validations="",
server_index=None,
server_variables=None,
server_operation_index=None,
Expand Down Expand Up @@ -256,7 +229,6 @@ def __init__(
"""Password for HTTP basic authentication
"""
self.discard_unknown_keys = discard_unknown_keys
self.disabled_client_side_validations = disabled_client_side_validations
self.logger = {}
"""Logging Settings
"""
Expand Down Expand Up @@ -747,20 +719,3 @@ def timeout_millisec(self, value):
Update timeout milliseconds
"""
self._timeout_millisec = value

@property
def disabled_client_side_validations(self):
"""Return disable_client_side_validations."""
return self._disabled_client_side_validations

@disabled_client_side_validations.setter
def disabled_client_side_validations(self, value):
"""Update disable_client_side_validations."""
self._disabled_client_side_validations = {}

if isinstance(value, str) and value:
s = set(filter(None, value.split(",")))
for v in s:
if v not in JSON_SCHEMA_VALIDATION_KEYWORDS:
raise FgaValidationException(f"Invalid keyword: '{v}''")
self._disabled_client_side_validations = s
8 changes: 0 additions & 8 deletions openfga_sdk/models/assertion.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,6 @@ def contextual_tuples(self, contextual_tuples):
:param contextual_tuples: The contextual_tuples of this Assertion.
:type contextual_tuples: list[TupleKey]
"""
if (
self.local_vars_configuration.client_side_validation
and contextual_tuples is not None
and len(contextual_tuples) > 20
):
raise ValueError(
"Invalid value for `contextual_tuples`, number of items must be less than or equal to `20`"
)

self._contextual_tuples = contextual_tuples

Expand Down
24 changes: 0 additions & 24 deletions openfga_sdk/models/assertion_tuple_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,6 @@ def object(self, object):
"""
if self.local_vars_configuration.client_side_validation and object is None:
raise ValueError("Invalid value for `object`, must not be `None`")
if (
self.local_vars_configuration.client_side_validation
and object is not None
and len(object) > 256
):
raise ValueError(
"Invalid value for `object`, length must be less than or equal to `256`"
)

self._object = object

Expand All @@ -105,14 +97,6 @@ def relation(self, relation):
"""
if self.local_vars_configuration.client_side_validation and relation is None:
raise ValueError("Invalid value for `relation`, must not be `None`")
if (
self.local_vars_configuration.client_side_validation
and relation is not None
and len(relation) > 50
):
raise ValueError(
"Invalid value for `relation`, length must be less than or equal to `50`"
)

self._relation = relation

Expand All @@ -136,14 +120,6 @@ def user(self, user):
"""
if self.local_vars_configuration.client_side_validation and user is None:
raise ValueError("Invalid value for `user`, must not be `None`")
if (
self.local_vars_configuration.client_side_validation
and user is not None
and len(user) > 512
):
raise ValueError(
"Invalid value for `user`, length must be less than or equal to `512`"
)

self._user = user

Expand Down
24 changes: 0 additions & 24 deletions openfga_sdk/models/check_request_tuple_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,6 @@ def user(self, user):
"""
if self.local_vars_configuration.client_side_validation and user is None:
raise ValueError("Invalid value for `user`, must not be `None`")
if (
self.local_vars_configuration.client_side_validation
and user is not None
and len(user) > 512
):
raise ValueError(
"Invalid value for `user`, length must be less than or equal to `512`"
)

self._user = user

Expand All @@ -105,14 +97,6 @@ def relation(self, relation):
"""
if self.local_vars_configuration.client_side_validation and relation is None:
raise ValueError("Invalid value for `relation`, must not be `None`")
if (
self.local_vars_configuration.client_side_validation
and relation is not None
and len(relation) > 50
):
raise ValueError(
"Invalid value for `relation`, length must be less than or equal to `50`"
)

self._relation = relation

Expand All @@ -136,14 +120,6 @@ def object(self, object):
"""
if self.local_vars_configuration.client_side_validation and object is None:
raise ValueError("Invalid value for `object`, must not be `None`")
if (
self.local_vars_configuration.client_side_validation
and object is not None
and len(object) > 256
):
raise ValueError(
"Invalid value for `object`, length must be less than or equal to `256`"
)

self._object = object

Expand Down
8 changes: 0 additions & 8 deletions openfga_sdk/models/contextual_tuple_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,6 @@ def tuple_keys(self, tuple_keys):
"""
if self.local_vars_configuration.client_side_validation and tuple_keys is None:
raise ValueError("Invalid value for `tuple_keys`, must not be `None`")
if (
self.local_vars_configuration.client_side_validation
and tuple_keys is not None
and len(tuple_keys) > 100
):
raise ValueError(
"Invalid value for `tuple_keys`, number of items must be less than or equal to `100`"
)

self._tuple_keys = tuple_keys

Expand Down
16 changes: 0 additions & 16 deletions openfga_sdk/models/expand_request_tuple_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,6 @@ def relation(self, relation):
"""
if self.local_vars_configuration.client_side_validation and relation is None:
raise ValueError("Invalid value for `relation`, must not be `None`")
if (
self.local_vars_configuration.client_side_validation
and relation is not None
and len(relation) > 50
):
raise ValueError(
"Invalid value for `relation`, length must be less than or equal to `50`"
)

self._relation = relation

Expand All @@ -101,14 +93,6 @@ def object(self, object):
"""
if self.local_vars_configuration.client_side_validation and object is None:
raise ValueError("Invalid value for `object`, must not be `None`")
if (
self.local_vars_configuration.client_side_validation
and object is not None
and len(object) > 256
):
raise ValueError(
"Invalid value for `object`, length must be less than or equal to `256`"
)

self._object = object

Expand Down
16 changes: 0 additions & 16 deletions openfga_sdk/models/list_objects_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,22 +177,6 @@ def user(self, user):
"""
if self.local_vars_configuration.client_side_validation and user is None:
raise ValueError("Invalid value for `user`, must not be `None`")
if (
self.local_vars_configuration.client_side_validation
and user is not None
and len(user) > 512
):
raise ValueError(
"Invalid value for `user`, length must be less than or equal to `512`"
)
if (
self.local_vars_configuration.client_side_validation
and user is not None
and len(user) < 1
):
raise ValueError(
"Invalid value for `user`, length must be greater than or equal to `1`"
)

self._user = user

Expand Down
24 changes: 0 additions & 24 deletions openfga_sdk/models/list_users_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,22 +182,6 @@ def user_filters(self, user_filters):
and user_filters is None
):
raise ValueError("Invalid value for `user_filters`, must not be `None`")
if (
self.local_vars_configuration.client_side_validation
and user_filters is not None
and len(user_filters) > 1
):
raise ValueError(
"Invalid value for `user_filters`, number of items must be less than or equal to `1`"
)
if (
self.local_vars_configuration.client_side_validation
and user_filters is not None
and len(user_filters) < 1
):
raise ValueError(
"Invalid value for `user_filters`, number of items must be greater than or equal to `1`"
)

self._user_filters = user_filters

Expand All @@ -219,14 +203,6 @@ def contextual_tuples(self, contextual_tuples):
:param contextual_tuples: The contextual_tuples of this ListUsersRequest.
:type contextual_tuples: list[TupleKey]
"""
if (
self.local_vars_configuration.client_side_validation
and contextual_tuples is not None
and len(contextual_tuples) > 100
):
raise ValueError(
"Invalid value for `contextual_tuples`, number of items must be less than or equal to `100`"
)

self._contextual_tuples = contextual_tuples

Expand Down
16 changes: 0 additions & 16 deletions openfga_sdk/models/read_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,22 +114,6 @@ def page_size(self, page_size):
:param page_size: The page_size of this ReadRequest.
:type page_size: int
"""
if (
self.local_vars_configuration.client_side_validation
and page_size is not None
and page_size > 100
):
raise ValueError(
"Invalid value for `page_size`, must be a value less than or equal to `100`"
)
if (
self.local_vars_configuration.client_side_validation
and page_size is not None
and page_size < 1
):
raise ValueError(
"Invalid value for `page_size`, must be a value greater than or equal to `1`"
)

self._page_size = page_size

Expand Down
Loading
Loading