Jelajahi Sumber

[REF-3157] Avoid SQLModel metaclass conflict (#3610)

Ensure that reflex.utils.compat is loaded whenever `reflex` itself is imported
to try and avoid the sqlmodel metaclass conflict error that arises when
sqlmodel is imported first with pydantic v2, but reflex Model inherits from
rx.Base which is based on pydantic v1.

Fix #3515
Masen Furer 10 bulan lalu
induk
melakukan
7cbd2848ce
2 mengubah file dengan 10 tambahan dan 1 penghapusan
  1. 7 1
      reflex/__init__.py
  2. 3 0
      reflex/__init__.pyi

+ 7 - 1
reflex/__init__.py

@@ -84,12 +84,18 @@ In the example above, you will be able to do `rx.list`
 
 from __future__ import annotations
 
-from reflex.utils import lazy_loader
+from reflex.utils import (
+    compat,  # for side-effects
+    lazy_loader,
+)
 
 # import this here explicitly to avoid returning the page module since page attr has the
 # same name as page module(page.py)
 from .page import page as page
 
+# Remove the `compat` name from the namespace, it was imported for side-effects only.
+del compat
+
 RADIX_THEMES_MAPPING: dict = {
     "components.radix.themes.base": ["color_mode", "theme", "theme_panel"],
     "components.radix.themes.color_mode": ["color_mode"],

+ 3 - 0
reflex/__init__.pyi

@@ -3,6 +3,8 @@
 # This file was generated by `reflex/utils/pyi_generator.py`!
 # ------------------------------------------------------
 
+from reflex.utils import compat
+
 from . import admin as admin
 from . import app as app
 from . import base as base
@@ -190,6 +192,7 @@ from .utils.serializers import serializer as serializer
 from .vars import Var as Var
 from .vars import cached_var as cached_var
 
+del compat
 RADIX_THEMES_MAPPING: dict
 RADIX_THEMES_COMPONENTS_MAPPING: dict
 RADIX_THEMES_LAYOUT_MAPPING: dict