From 7cbd2848ce8b985f325d2aece7901f4a878984f5 Mon Sep 17 00:00:00 2001 From: Masen Furer Date: Wed, 3 Jul 2024 06:58:21 -0700 Subject: [PATCH] [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 --- reflex/__init__.py | 8 +++++++- reflex/__init__.pyi | 3 +++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/reflex/__init__.py b/reflex/__init__.py index 4b2dc7e8a..faf3e087e 100644 --- a/reflex/__init__.py +++ b/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"], diff --git a/reflex/__init__.pyi b/reflex/__init__.pyi index 61e7d1f9d..8fe42cfb3 100644 --- a/reflex/__init__.pyi +++ b/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