]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
remove errant NO_KEY symbol
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 27 Dec 2022 22:20:07 +0000 (17:20 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 27 Dec 2022 22:22:44 +0000 (17:22 -0500)
the symbol from base is used in the event API and is
passed along from attributes here.

for the additional use where it's an exception case for
attribute name as passed by hybrid, use a different symbol name.

Change-Id: I8c5c0e71d19185ebec64f2fcbfe1e9be74e54287

lib/sqlalchemy/ext/hybrid.py
lib/sqlalchemy/orm/attributes.py

index de9ab52be0d831ee4ae27fc603a91501620c1328..a5dc3158395cc7fb673cc793ad2fecc4b4cac599 100644 (file)
@@ -1122,7 +1122,7 @@ class hybrid_property(interfaces.InspectionAttrInfo, ORMDescriptor[_T]):
                         name = self.__name__
                         break
             else:
-                name = attributes.NO_KEY
+                name = attributes._UNKNOWN_ATTR_KEY  # type: ignore[assignment]
 
             return proxy_attr(
                 owner,
index 5e6852cbf08c59be837ad0e53eb4db746f2f0a65..65d6970a97d2c5b760d1252707fd7bc832e5da81 100644 (file)
@@ -55,6 +55,7 @@ from .base import Mapped as Mapped  # noqa
 from .base import NEVER_SET  # noqa
 from .base import NO_AUTOFLUSH
 from .base import NO_CHANGE  # noqa
+from .base import NO_KEY
 from .base import NO_RAISE
 from .base import NO_VALUE
 from .base import NON_PERSISTENT_OK  # noqa
@@ -115,20 +116,16 @@ if TYPE_CHECKING:
 _T = TypeVar("_T")
 
 
-class NoKey(str):
-    pass
-
-
 _AllPendingType = Sequence[
     Tuple[Optional["InstanceState[Any]"], Optional[object]]
 ]
 
-NO_KEY = NoKey("no name")
-
 SelfQueryableAttribute = TypeVar(
     "SelfQueryableAttribute", bound="QueryableAttribute[Any]"
 )
 
+_UNKNOWN_ATTR_KEY = object()
+
 
 @inspection._self_inspects
 class QueryableAttribute(
@@ -327,7 +324,12 @@ class QueryableAttribute(
     def _memoized_attr_expression(self) -> ColumnElement[_T]:
         annotations: _AnnotationDict
 
-        if self.key is NO_KEY:
+        # applies only to Proxy() as used by hybrid.
+        # currently is an exception to typing rather than feeding through
+        # non-string keys.
+        # ideally Proxy() would have a separate set of methods to deal
+        # with this case.
+        if self.key is _UNKNOWN_ATTR_KEY:  # type: ignore[comparison-overlap]
             annotations = {"entity_namespace": self._entity_namespace}
         else:
             annotations = {