Skip to content

Commit 99f45c7

Browse files
authored
Port retry and client validation changes (#155)
2 parents 1c690e8 + 71805f0 commit 99f45c7

20 files changed

+8
-323
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

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

5+
- feat: remove client-side validation - thanks @GMorris-professional (#155)
6+
- fix: change default max retry limit to 3 from 15 - thanks @ovindu-a (#155)
7+
58
## v0.8.1
69

710
### [0.8.1](https://github.com/openfga/python-sdk/compare/v0.8.0...v0.8.1) (2024-11-26)

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ import openfga_sdk
122122

123123
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.
124124

125-
> The `OpenFgaClient` will by default retry API requests up to 15 times on 429 and 5xx errors.
125+
> The `OpenFgaClient` will by default retry API requests up to 3 times on 429 and 5xx errors.
126126
127127
#### No Credentials
128128

@@ -720,7 +720,7 @@ response = await fga_client.check(body, options)
720720
##### Batch Check
721721

722722
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.
723-
If 429s or 5xxs are encountered, the underlying check will retry up to 15 times before giving up.
723+
If 429s or 5xxs are encountered, the underlying check will retry up to 3 times before giving up.
724724

725725
```python
726726
# from openfga_sdk import OpenFgaClient
@@ -1015,7 +1015,7 @@ response = await fga_client.write_assertions(body, options)
10151015

10161016
### Retries
10171017

1018-
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.
1018+
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.
10191019

10201020
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.
10211021

openfga_sdk/configuration.py

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,6 @@
3030
from openfga_sdk.telemetry.histograms import TelemetryHistogram
3131
from openfga_sdk.validation import is_well_formed_ulid_string
3232

33-
JSON_SCHEMA_VALIDATION_KEYWORDS = {
34-
"multipleOf",
35-
"maximum",
36-
"exclusiveMaximum",
37-
"minimum",
38-
"exclusiveMinimum",
39-
"maxLength",
40-
"minLength",
41-
"pattern",
42-
"maxItems",
43-
"minItems",
44-
}
45-
4633

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

59-
def __init__(self, max_retry=15, min_wait_in_ms=100):
46+
def __init__(self, max_retry=3, min_wait_in_ms=100):
6047
self._max_retry = max_retry
6148
self._min_wait_in_ms = min_wait_in_ms
6249

@@ -144,19 +131,6 @@ class Configuration:
144131
then all undeclared properties received by the server are injected into the
145132
additional properties map. In that case, there are undeclared properties, and
146133
nothing to discard.
147-
:param disabled_client_side_validations (string): Comma-separated list of
148-
JSON schema validation keywords to disable JSON schema structural validation
149-
rules. The following keywords may be specified: multipleOf, maximum,
150-
exclusiveMaximum, minimum, exclusiveMinimum, maxLength, minLength, pattern,
151-
maxItems, minItems.
152-
By default, the validation is performed for data generated locally by the client
153-
and data received from the server, independent of any validation performed by
154-
the server side. If the input data does not satisfy the JSON schema validation
155-
rules specified in the OpenAPI document, an exception is raised.
156-
If disabled_client_side_validations is set, structural validation is
157-
disabled. This can be useful to troubleshoot data validation problem, such as
158-
when the OpenAPI document validation rules do not match the actual API data
159-
received by the server.
160134
:param server_index: Index to servers configuration.
161135
:param server_variables: Mapping with string values to replace variables in
162136
templated server configuration. The validation of enums is performed for
@@ -186,7 +160,6 @@ def __init__(
186160
username=None,
187161
password=None,
188162
discard_unknown_keys=False,
189-
disabled_client_side_validations="",
190163
server_index=None,
191164
server_variables=None,
192165
server_operation_index=None,
@@ -256,7 +229,6 @@ def __init__(
256229
"""Password for HTTP basic authentication
257230
"""
258231
self.discard_unknown_keys = discard_unknown_keys
259-
self.disabled_client_side_validations = disabled_client_side_validations
260232
self.logger = {}
261233
"""Logging Settings
262234
"""
@@ -747,20 +719,3 @@ def timeout_millisec(self, value):
747719
Update timeout milliseconds
748720
"""
749721
self._timeout_millisec = value
750-
751-
@property
752-
def disabled_client_side_validations(self):
753-
"""Return disable_client_side_validations."""
754-
return self._disabled_client_side_validations
755-
756-
@disabled_client_side_validations.setter
757-
def disabled_client_side_validations(self, value):
758-
"""Update disable_client_side_validations."""
759-
self._disabled_client_side_validations = {}
760-
761-
if isinstance(value, str) and value:
762-
s = set(filter(None, value.split(",")))
763-
for v in s:
764-
if v not in JSON_SCHEMA_VALIDATION_KEYWORDS:
765-
raise FgaValidationException(f"Invalid keyword: '{v}''")
766-
self._disabled_client_side_validations = s

openfga_sdk/models/assertion.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,6 @@ def contextual_tuples(self, contextual_tuples):
137137
:param contextual_tuples: The contextual_tuples of this Assertion.
138138
:type contextual_tuples: list[TupleKey]
139139
"""
140-
if (
141-
self.local_vars_configuration.client_side_validation
142-
and contextual_tuples is not None
143-
and len(contextual_tuples) > 20
144-
):
145-
raise ValueError(
146-
"Invalid value for `contextual_tuples`, number of items must be less than or equal to `20`"
147-
)
148140

149141
self._contextual_tuples = contextual_tuples
150142

openfga_sdk/models/assertion_tuple_key.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,6 @@ def object(self, object):
7474
"""
7575
if self.local_vars_configuration.client_side_validation and object is None:
7676
raise ValueError("Invalid value for `object`, must not be `None`")
77-
if (
78-
self.local_vars_configuration.client_side_validation
79-
and object is not None
80-
and len(object) > 256
81-
):
82-
raise ValueError(
83-
"Invalid value for `object`, length must be less than or equal to `256`"
84-
)
8577

8678
self._object = object
8779

@@ -105,14 +97,6 @@ def relation(self, relation):
10597
"""
10698
if self.local_vars_configuration.client_side_validation and relation is None:
10799
raise ValueError("Invalid value for `relation`, must not be `None`")
108-
if (
109-
self.local_vars_configuration.client_side_validation
110-
and relation is not None
111-
and len(relation) > 50
112-
):
113-
raise ValueError(
114-
"Invalid value for `relation`, length must be less than or equal to `50`"
115-
)
116100

117101
self._relation = relation
118102

@@ -136,14 +120,6 @@ def user(self, user):
136120
"""
137121
if self.local_vars_configuration.client_side_validation and user is None:
138122
raise ValueError("Invalid value for `user`, must not be `None`")
139-
if (
140-
self.local_vars_configuration.client_side_validation
141-
and user is not None
142-
and len(user) > 512
143-
):
144-
raise ValueError(
145-
"Invalid value for `user`, length must be less than or equal to `512`"
146-
)
147123

148124
self._user = user
149125

openfga_sdk/models/check_request_tuple_key.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,6 @@ def user(self, user):
7474
"""
7575
if self.local_vars_configuration.client_side_validation and user is None:
7676
raise ValueError("Invalid value for `user`, must not be `None`")
77-
if (
78-
self.local_vars_configuration.client_side_validation
79-
and user is not None
80-
and len(user) > 512
81-
):
82-
raise ValueError(
83-
"Invalid value for `user`, length must be less than or equal to `512`"
84-
)
8577

8678
self._user = user
8779

@@ -105,14 +97,6 @@ def relation(self, relation):
10597
"""
10698
if self.local_vars_configuration.client_side_validation and relation is None:
10799
raise ValueError("Invalid value for `relation`, must not be `None`")
108-
if (
109-
self.local_vars_configuration.client_side_validation
110-
and relation is not None
111-
and len(relation) > 50
112-
):
113-
raise ValueError(
114-
"Invalid value for `relation`, length must be less than or equal to `50`"
115-
)
116100

117101
self._relation = relation
118102

@@ -136,14 +120,6 @@ def object(self, object):
136120
"""
137121
if self.local_vars_configuration.client_side_validation and object is None:
138122
raise ValueError("Invalid value for `object`, must not be `None`")
139-
if (
140-
self.local_vars_configuration.client_side_validation
141-
and object is not None
142-
and len(object) > 256
143-
):
144-
raise ValueError(
145-
"Invalid value for `object`, length must be less than or equal to `256`"
146-
)
147123

148124
self._object = object
149125

openfga_sdk/models/contextual_tuple_keys.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,6 @@ def tuple_keys(self, tuple_keys):
6868
"""
6969
if self.local_vars_configuration.client_side_validation and tuple_keys is None:
7070
raise ValueError("Invalid value for `tuple_keys`, must not be `None`")
71-
if (
72-
self.local_vars_configuration.client_side_validation
73-
and tuple_keys is not None
74-
and len(tuple_keys) > 100
75-
):
76-
raise ValueError(
77-
"Invalid value for `tuple_keys`, number of items must be less than or equal to `100`"
78-
)
7971

8072
self._tuple_keys = tuple_keys
8173

openfga_sdk/models/expand_request_tuple_key.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,6 @@ def relation(self, relation):
7070
"""
7171
if self.local_vars_configuration.client_side_validation and relation is None:
7272
raise ValueError("Invalid value for `relation`, must not be `None`")
73-
if (
74-
self.local_vars_configuration.client_side_validation
75-
and relation is not None
76-
and len(relation) > 50
77-
):
78-
raise ValueError(
79-
"Invalid value for `relation`, length must be less than or equal to `50`"
80-
)
8173

8274
self._relation = relation
8375

@@ -101,14 +93,6 @@ def object(self, object):
10193
"""
10294
if self.local_vars_configuration.client_side_validation and object is None:
10395
raise ValueError("Invalid value for `object`, must not be `None`")
104-
if (
105-
self.local_vars_configuration.client_side_validation
106-
and object is not None
107-
and len(object) > 256
108-
):
109-
raise ValueError(
110-
"Invalid value for `object`, length must be less than or equal to `256`"
111-
)
11296

11397
self._object = object
11498

openfga_sdk/models/list_objects_request.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -177,22 +177,6 @@ def user(self, user):
177177
"""
178178
if self.local_vars_configuration.client_side_validation and user is None:
179179
raise ValueError("Invalid value for `user`, must not be `None`")
180-
if (
181-
self.local_vars_configuration.client_side_validation
182-
and user is not None
183-
and len(user) > 512
184-
):
185-
raise ValueError(
186-
"Invalid value for `user`, length must be less than or equal to `512`"
187-
)
188-
if (
189-
self.local_vars_configuration.client_side_validation
190-
and user is not None
191-
and len(user) < 1
192-
):
193-
raise ValueError(
194-
"Invalid value for `user`, length must be greater than or equal to `1`"
195-
)
196180

197181
self._user = user
198182

openfga_sdk/models/list_users_request.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -182,22 +182,6 @@ def user_filters(self, user_filters):
182182
and user_filters is None
183183
):
184184
raise ValueError("Invalid value for `user_filters`, must not be `None`")
185-
if (
186-
self.local_vars_configuration.client_side_validation
187-
and user_filters is not None
188-
and len(user_filters) > 1
189-
):
190-
raise ValueError(
191-
"Invalid value for `user_filters`, number of items must be less than or equal to `1`"
192-
)
193-
if (
194-
self.local_vars_configuration.client_side_validation
195-
and user_filters is not None
196-
and len(user_filters) < 1
197-
):
198-
raise ValueError(
199-
"Invalid value for `user_filters`, number of items must be greater than or equal to `1`"
200-
)
201185

202186
self._user_filters = user_filters
203187

@@ -219,14 +203,6 @@ def contextual_tuples(self, contextual_tuples):
219203
:param contextual_tuples: The contextual_tuples of this ListUsersRequest.
220204
:type contextual_tuples: list[TupleKey]
221205
"""
222-
if (
223-
self.local_vars_configuration.client_side_validation
224-
and contextual_tuples is not None
225-
and len(contextual_tuples) > 100
226-
):
227-
raise ValueError(
228-
"Invalid value for `contextual_tuples`, number of items must be less than or equal to `100`"
229-
)
230206

231207
self._contextual_tuples = contextual_tuples
232208

0 commit comments

Comments
 (0)