Skip to content

Update surrealdb integration for 2.x#1899

Merged
alexmojaki merged 1 commit into
mainfrom
update-surrealdb-2
May 4, 2026
Merged

Update surrealdb integration for 2.x#1899
alexmojaki merged 1 commit into
mainfrom
update-surrealdb-2

Conversation

@alexmojaki
Copy link
Copy Markdown
Collaborator

Summary

  • Bumps surrealdb from 1.0.8 → 2.0.0 in the lockfile.
  • Updates the integration to handle PEP 604 (X | Y) unions in _is_complex_type and to derive the message template from the base SyncTemplate signature, so all subclasses share the same span template regardless of subclass-specific overrides (e.g. WebSocket connections add an optional session_id parameter in 2.x).

Why split out

This was originally part of #1898 (general dep update). It needs more scrutiny than a routine bump because the integration has to adapt to surrealdb 2.x's API surface, so it's been pinned <2 there and lives here on its own.

Test plan

  • CI passes on Python 3.10–3.14
  • tests/otel_integrations/test_surrealdb.py passes unchanged on both Python 3.12 and 3.14

@cloudflare-workers-and-pages
Copy link
Copy Markdown

Deploying logfire-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 2342005
Status: ✅  Deploy successful!
Preview URL: https://a597aac5.logfire-docs.pages.dev
Branch Preview URL: https://update-surrealdb-2.logfire-docs.pages.dev

View logs

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 2 files

Confidence score: 2/5

  • High-confidence compatibility bug in logfire/_internal/integrations/surrealdb.py: checking types.UnionType is not Python 3.9-safe and can raise AttributeError at runtime.
  • This is a concrete user-facing regression risk for Python 3.9 environments, so the merge risk is elevated despite the issue being localized to one integration file.
  • Pay close attention to logfire/_internal/integrations/surrealdb.py - union-type detection needs a Python 3.9-safe approach to avoid runtime failures.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="logfire/_internal/integrations/surrealdb.py">

<violation number="1" location="logfire/_internal/integrations/surrealdb.py:30">
P1: This union-type check is not Python 3.9-safe: `types.UnionType` does not exist there and can raise `AttributeError` at runtime.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

if tp in (str, bool, int, float, type(None), uuid.UUID, Table, RecordIdType):
return False
if origin is Union: # pragma: no branch
if origin is Union or origin is types.UnionType: # pragma: no branch
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: This union-type check is not Python 3.9-safe: types.UnionType does not exist there and can raise AttributeError at runtime.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At logfire/_internal/integrations/surrealdb.py, line 30:

<comment>This union-type check is not Python 3.9-safe: `types.UnionType` does not exist there and can raise `AttributeError` at runtime.</comment>

<file context>
@@ -26,7 +27,7 @@ def _is_complex_type(tp: type | type[Value]) -> bool:
     if tp in (str, bool, int, float, type(None), uuid.UUID, Table, RecordIdType):
         return False
-    if origin is Union:  # pragma: no branch
+    if origin is Union or origin is types.UnionType:  # pragma: no branch
         args = get_args(tp)
         return any(_is_complex_type(arg) for arg in args)
</file context>
Suggested change
if origin is Union or origin is types.UnionType: # pragma: no branch
if origin is Union or (hasattr(types, 'UnionType') and origin is types.UnionType): # pragma: no branch

@alexmojaki alexmojaki merged commit 4b81787 into main May 4, 2026
19 checks passed
@alexmojaki alexmojaki deleted the update-surrealdb-2 branch May 4, 2026 11:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant