summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm/mapper.py
diff options
context:
space:
mode:
authorMiłosz Stypiński <mstypins@cisco.com>2021-06-24 12:21:30 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2021-06-28 11:34:00 -0400
commit5933a5dc2ec29248e1b8842245c8ddabd819c6dd (patch)
treea48a171f3c0a491655064719c3cb1fc3d38382fb /lib/sqlalchemy/orm/mapper.py
parentb02087666e4ff9199ea221fbee37be8438ecd7f0 (diff)
downloadsqlalchemy-5933a5dc2ec29248e1b8842245c8ddabd819c6dd.tar.gz
Be less fiscal regarding validators functions
Adjusted the check in the mapper for a callable object that is used as a ``@validates`` validator function or a ``@reconstructor`` reconstruction function, to check for "callable" more liberally such as to accommodate objects based on fundamental attributes like ``__func__`` and ``__call___``, rather than testing for ``MethodType`` / ``FunctionType``, allowing things like cython functions to work properly. Pull request courtesy Miłosz Stypiński. Fixes: #6538 Closes: #6539 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/6539 Pull-request-sha: ed1d7fe5c9386bab0416ff32095afc777c26b6ca Change-Id: I8350558bc9a9ba58f43e48e12ce25a0b30e4d767
Diffstat (limited to 'lib/sqlalchemy/orm/mapper.py')
-rw-r--r--lib/sqlalchemy/orm/mapper.py5
1 files changed, 2 insertions, 3 deletions
diff --git a/lib/sqlalchemy/orm/mapper.py b/lib/sqlalchemy/orm/mapper.py
index 378c65278..bab2eb6b9 100644
--- a/lib/sqlalchemy/orm/mapper.py
+++ b/lib/sqlalchemy/orm/mapper.py
@@ -19,7 +19,6 @@ from __future__ import absolute_import
from collections import deque
from itertools import chain
import sys
-import types
import weakref
from . import attributes
@@ -1260,9 +1259,9 @@ class Mapper(
for key, method in util.iterate_attributes(self.class_):
if key == "__init__" and hasattr(method, "_sa_original_init"):
method = method._sa_original_init
- if isinstance(method, types.MethodType):
+ if hasattr(method, "__func__"):
method = method.__func__
- if isinstance(method, types.FunctionType):
+ if callable(method):
if hasattr(method, "__sa_reconstructor__"):
self._reconstructor = method
event.listen(manager, "load", _event_on_load, raw=True)