]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Fixes: #6646
authorjason3gb <jason3gb@gmail.com>
Mon, 21 Jun 2021 17:08:50 +0000 (01:08 +0800)
committerjason3gb <jason3gb@gmail.com>
Tue, 22 Jun 2021 10:54:27 +0000 (18:54 +0800)
doc/build/changelog/unreleased_14/6646.rst [new file with mode: 0644]
lib/sqlalchemy/sql/sqltypes.py
test/sql/test_types.py

diff --git a/doc/build/changelog/unreleased_14/6646.rst b/doc/build/changelog/unreleased_14/6646.rst
new file mode 100644 (file)
index 0000000..76d4aad
--- /dev/null
@@ -0,0 +1,8 @@
+.. change::
+    :tags: usecase, type
+    :tickets: 6646
+
+    Add a impl parameter to :class:`.PickleType` constructor, so the user
+    can customize the default implementation to avoid the issue that the
+    default LargeBinary impl might not be big enough to store the binary
+    object.
\ No newline at end of file
index 4f8654afd9d26245f06e6a48d61ada40bf96adeb..b700445f395b3143538513167a7be067d84ee1a2 100644 (file)
@@ -1783,7 +1783,11 @@ class PickleType(TypeDecorator):
     cache_ok = True
 
     def __init__(
-        self, protocol=pickle.HIGHEST_PROTOCOL, pickler=None, comparator=None
+        self,
+        protocol=pickle.HIGHEST_PROTOCOL,
+        pickler=None,
+        comparator=None,
+        impl=None,
     ):
         """
         Construct a PickleType.
@@ -1798,12 +1802,20 @@ class PickleType(TypeDecorator):
           to compare values of this type.  If left as ``None``,
           the Python "equals" operator is used to compare values.
 
+        :param impl: Any implementation class that support storing
+          binary object. (e.g. :class: `.mysql.LONGBLOB`).
+          If let as ``None``, the impl would use class's default impl
+          `:class:`.LargeBinary`
+
         """
         self.protocol = protocol
         self.pickler = pickler or pickle
         self.comparator = comparator
         super(PickleType, self).__init__()
 
+        if impl:
+            self.impl = to_instance(impl)
+
     def __reduce__(self):
         return PickleType, (self.protocol, None, self.comparator)
 
index 9db0fee3b07718095eab1ca014d73c9edb87d0dc..d4ef25b4b95da3065461345b151bd4fe57cb92ef 100644 (file)
@@ -3809,6 +3809,11 @@ class PickleTest(fixtures.TestBase):
         ):
             assert p1.compare_values(p1.copy_value(obj), obj)
 
+    def test_customized_impl(self):
+        p1 = PickleType(impl=mysql.LONGBLOB)
+
+        assert isinstance(p1.impl, mysql.LONGBLOB)
+
 
 class CallableTest(fixtures.TestBase):
     @testing.provide_metadata