gofeatureflag-python-provider 0.4.1__tar.gz → 0.4.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: gofeatureflag-python-provider
3
- Version: 0.4.1
3
+ Version: 0.4.3
4
4
  Summary: GO Feature Flag provider for OpenFeature
5
5
  License: Apache-2.0
6
6
  Keywords: feature flags,feature toggles,go-feature-flag,gofeatureflag,openfeature,open-feature
@@ -15,8 +15,7 @@ Classifier: Programming Language :: Python :: 3.12
15
15
  Classifier: Programming Language :: Python :: 3.13
16
16
  Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
17
17
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
18
- Requires-Dist: asyncio (>=3.4.3,<4.0.0)
19
- Requires-Dist: openfeature-sdk (>=0.5.0,<0.8.0)
18
+ Requires-Dist: openfeature-sdk (>=0.5.0,<0.9.0)
20
19
  Requires-Dist: pydantic (>=2.5.2,<3.0.0)
21
20
  Requires-Dist: pylru (>=1.2.1,<2.0.0)
22
21
  Requires-Dist: rel (>=0.4.9,<0.5.0)
@@ -19,6 +19,7 @@ from openfeature.exception import (
19
19
  ErrorCode,
20
20
  FlagNotFoundError,
21
21
  GeneralError,
22
+ InvalidContextError,
22
23
  OpenFeatureError,
23
24
  TypeMismatchError,
24
25
  )
@@ -69,9 +70,14 @@ class GoFeatureFlagProvider(BaseModel, AbstractProvider, metaclass=CombinedMetac
69
70
  websocket.enableTrace(self.options.debug)
70
71
  self._ws = websocket.WebSocketApp(
71
72
  self._build_websocket_uri(),
73
+ on_open=self.on_open,
72
74
  on_message=self._websocket_message_handler,
73
75
  )
74
76
 
77
+ def on_open(self, ws):
78
+ if self._cache is not None:
79
+ self._cache.clear()
80
+
75
81
  def initialize(self, evaluation_context: EvaluationContext) -> None:
76
82
  """
77
83
  initialize is called when the provider is initialized.
@@ -178,11 +184,11 @@ class GoFeatureFlagProvider(BaseModel, AbstractProvider, metaclass=CombinedMetac
178
184
  user=goff_evaluation_context,
179
185
  defaultValue=default_value,
180
186
  )
181
- evaluation_context_hash = goff_evaluation_context.hash()
187
+ cache_key = f"{flag_key}:{goff_evaluation_context.hash()}"
182
188
  is_from_cache = False
183
189
 
184
- if evaluation_context_hash in self._cache:
185
- response_body = self._cache[evaluation_context_hash]
190
+ if cache_key in self._cache:
191
+ response_body = self._cache[cache_key]
186
192
  is_from_cache = True
187
193
  else:
188
194
  headers = {"Content-Type": "application/json"}
@@ -210,23 +216,36 @@ class GoFeatureFlagProvider(BaseModel, AbstractProvider, metaclass=CombinedMetac
210
216
  body=goff_request.model_dump_json(),
211
217
  )
212
218
 
219
+ response_body = response.data
220
+
221
+ # Handle 404 error code
213
222
  if response.status == HTTPStatus.NOT_FOUND.value:
214
223
  raise FlagNotFoundError(
215
224
  "flag {} was not found in your configuration".format(flag_key)
216
225
  )
217
226
 
218
- if int(response.status) >= HTTPStatus.BAD_REQUEST.value:
227
+ # Handle 400 error code
228
+ if int(response.status) == HTTPStatus.BAD_REQUEST.value:
229
+ response_dict = json.loads(response_body)
230
+ error_message = response_dict.get("message")
231
+
232
+ if error_message is None:
233
+ error_message = "no error message given."
234
+
235
+ raise InvalidContextError("Invalid context: " + error_message)
236
+
237
+ # Handle every error response above 400
238
+ if int(response.status) > HTTPStatus.BAD_REQUEST.value:
219
239
  raise GeneralError(
220
240
  "impossible to contact GO Feature Flag relay proxy instance"
221
241
  )
222
- response_body = response.data
223
242
 
224
243
  response_flag_evaluation = ResponseFlagEvaluation.model_validate_json(
225
244
  response_body
226
245
  )
227
246
 
228
247
  if response_flag_evaluation.cacheable:
229
- self._cache[evaluation_context_hash] = response_body
248
+ self._cache[cache_key] = response_body
230
249
 
231
250
  if original_type == int:
232
251
  response_json = json.loads(response_body)
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "gofeatureflag-python-provider"
3
- version = "0.4.1"
3
+ version = "0.4.3"
4
4
  description = "GO Feature Flag provider for OpenFeature"
5
5
  license = "Apache-2.0"
6
6
  authors = [ "Thomas Poignant" ]
@@ -28,13 +28,12 @@ classifiers = [
28
28
 
29
29
  [tool.poetry.dependencies]
30
30
  python = "^3.9"
31
- openfeature-sdk = ">=0.5.0,<0.8.0"
31
+ openfeature-sdk = ">=0.5.0,<0.9.0"
32
32
  pydantic = "^2.5.2"
33
33
  urllib3 = "^2.1.0"
34
34
  pylru = "^1.2.1"
35
35
  websocket-client = "^1.6.4"
36
36
  rel = "^0.4.9"
37
- asyncio = "^3.4.3"
38
37
 
39
38
  [tool.poetry.group.dev.dependencies]
40
39
  pytest = ">=7.4,<9.0"