Skip to content

Commit bd69bfb

Browse files
authored
Fixed span optionally None (permitio#747)
1 parent 6abc1d3 commit bd69bfb

File tree

4 files changed

+12
-8
lines changed

4 files changed

+12
-8
lines changed

packages/opal-client/opal_client/data/api.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ async def _handle_policy_data_update(span=None):
2727
)
2828
return {"status": "ok"}
2929
else:
30-
if span:
30+
if span is not None:
3131
span.set_status(trace.StatusCode.ERROR)
3232
span.set_attribute("error", True)
3333
span.set_attribute("error_type", "updater_disabled")
@@ -37,7 +37,7 @@ async def _handle_policy_data_update(span=None):
3737
)
3838
except Exception as e:
3939
logger.error(f"Error during data update: {str(e)}")
40-
if span:
40+
if span is not None:
4141
span.set_status(trace.StatusCode.ERROR)
4242
span.set_attribute("error", True)
4343
span.record_exception(e)

packages/opal-client/opal_client/policy/api.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ async def _handle_policy_update(span=None):
2121
return {"status": "ok"}
2222
except Exception as e:
2323
logger.error(f"Error during policy update: {str(e)}")
24-
if span:
24+
if span is not None:
2525
span.set_status(trace.StatusCode.ERROR)
2626
span.set_attribute("error", True)
2727
span.record_exception(e)

packages/opal-server/opal_server/policy/watcher/task.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,8 @@ async def trigger(self, topic: Topic, data: Any):
126126
pull)"""
127127
try:
128128
async with start_span("opal_server_policy_update") as span:
129-
span.set_attribute("topic", str(topic))
129+
if span is not None:
130+
span.set_attribute("topic", str(topic))
130131
await self._watcher.check_for_changes()
131132
except Exception as e:
132133
raise

packages/opal-server/opal_server/scopes/api.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ async def put_scope(
125125
claims: JWTClaims = Depends(authenticator),
126126
):
127127
async with start_span("opal_server_policy_update") as span:
128-
span.set_attribute("scope_id", scope_in.scope_id)
128+
if span is not None:
129+
span.set_attribute("scope_id", scope_in.scope_id)
129130
return await _handle_put_scope(force_fetch, scope_in, claims)
130131

131132
async def _handle_put_scope(
@@ -273,7 +274,8 @@ async def get_scope_policy(
273274
),
274275
):
275276
async with start_span("opal_server_policy_bundle_request") as span:
276-
span.set_attribute("scope_id", scope_id)
277+
if span is not None:
278+
span.set_attribute("scope_id", scope_id)
277279
policy_bundle = await _handle_get_scope_policy(scope_id, base_hash)
278280
policy_bundle_size_histogram = get_policy_bundle_size_histogram()
279281
if policy_bundle_size_histogram and policy_bundle.bundle:
@@ -380,7 +382,8 @@ async def publish_data_update_event(
380382
scope_id: str = Path(..., description="Scope ID"),
381383
):
382384
async with start_span("opal_server_data_update") as span:
383-
span.set_attribute("scope_id", scope_id)
385+
if span is not None:
386+
span.set_attribute("scope_id", scope_id)
384387
await _handle_publish_data_update_event(update, claims, scope_id, span)
385388

386389
async def _handle_publish_data_update_event(
@@ -399,7 +402,7 @@ async def _handle_publish_data_update_event(
399402
entry.topics = [f"data:{topic}" for topic in entry.topics]
400403
all_topics.update(entry.topics)
401404

402-
if span:
405+
if span is not None:
403406
span.set_attribute("entries_count", len(update.entries))
404407
span.set_attribute("topics", list(all_topics))
405408

0 commit comments

Comments
 (0)