cloudpipe / cloudpickle

Extended pickling support for Python objects
Other
1.64k stars 167 forks source link

loads method lost parent class in clouldpickle 2.0.0 #473

Closed a49a closed 2 years ago

a49a commented 2 years ago

When I bump clouldpickle from 1.2.2 to 2.0.0 in the Python Flink, the following PR CI throws an error that can not find method clear in parent class of MyProcessFunction

https://github.com/apache/flink/pull/19802

AttributeError: 'MyProcessFunction' object has no attribute 'clear'

But the following simple demo can't repeat this error.

import cloudpickle

class A():
    pass

class B():
    pass

class C(A, B):
    pass

class D(C):
    pass

d = D()
b = cloudpickle.dumps(d)
new_d = cloudpickle.loads(b)

The new_d directly extends A and B, the C class is lost, in the Python Flink environment. What would cause the parent class to be lost in the 2.0.0 version, and no error message?

The following is 1.2.2 version pkl file. MyProcessFunction extends ProcessWindowFunction. This is correct.

1462: (            MARK
 1463: \x8c             SHORT_BINUNICODE 'abc'
 1468: \x94             MEMOIZE    (as 114)
 1469: \x8c             SHORT_BINUNICODE 'ABCMeta'
 1478: \x94             MEMOIZE    (as 115)
 1479: \x93             STACK_GLOBAL
 1480: \x94             MEMOIZE    (as 116)
 1481: \x8c             SHORT_BINUNICODE 'MyProcessFunction'
 1500: \x94             MEMOIZE    (as 117)
 1501: h                BINGET     54
 1503: \x8c             SHORT_BINUNICODE 'ProcessWindowFunction'
 1526: \x94             MEMOIZE    (as 118)
 1527: \x93             STACK_GLOBAL
 1528: \x94             MEMOIZE    (as 119)
 1529: \x85             TUPLE1
 1530: \x94             MEMOIZE    (as 120)
 1531: }                EMPTY_DICT
 1532: \x94             MEMOIZE    (as 121)
 1533: \x8c             SHORT_BINUNICODE '__slots__'
 1544: \x94             MEMOIZE    (as 122)
 1545: )                EMPTY_TUPLE
 1546: s                SETITEM
 1547: \x8c             SHORT_BINUNICODE '575c7f84b2f148b9887f05e6b2d982ca'
 1581: \x94             MEMOIZE    (as 123)
 1582: N                NONE
 1583: t                TUPLE      (MARK at 1462)

The following is 2.0.0 version pkl file. MyProcessFunction extends Function and Generic. This is not correct.

 1462: (            MARK
 1463: \x8c             SHORT_BINUNICODE 'abc'
 1468: \x94             MEMOIZE    (as 114)
 1469: \x8c             SHORT_BINUNICODE 'ABCMeta'
 1478: \x94             MEMOIZE    (as 115)
 1479: \x93             STACK_GLOBAL
 1480: \x94             MEMOIZE    (as 116)
 1481: \x8c             SHORT_BINUNICODE 'MyProcessFunction'
 1500: \x94             MEMOIZE    (as 117)
 1501: h                BINGET     54
 1503: \x8c             SHORT_BINUNICODE 'Function'
 1513: \x94             MEMOIZE    (as 118)
 1514: \x93             STACK_GLOBAL
 1515: \x94             MEMOIZE    (as 119)
 1516: \x8c             SHORT_BINUNICODE '_operator'
 1527: \x94             MEMOIZE    (as 120)
 1528: \x8c             SHORT_BINUNICODE 'getitem'
 1537: \x94             MEMOIZE    (as 121)
 1538: \x93             STACK_GLOBAL
 1539: \x94             MEMOIZE    (as 122)
 1540: \x8c             SHORT_BINUNICODE 'typing'
 1548: \x94             MEMOIZE    (as 123)
 1549: \x8c             SHORT_BINUNICODE 'Generic'
 1558: \x94             MEMOIZE    (as 124)
 1559: \x93             STACK_GLOBAL
 1560: \x94             MEMOIZE    (as 125)
 1561: (                MARK
a49a commented 2 years ago

I resolve this problem by bumping to 2.1.0

tvalentyn commented 2 years ago

Is the error caused by a mismatch between cloudpickle version on client and server?

tvalentyn commented 2 years ago

Took a closer look at the description, sounds like a bug in 2.0.0

ogrisel commented 2 years ago

Closing as everybody seems to agree that this was fixed in 2.1.0.