From 1bb5350c5102362889be02c14304eaefb5bee6c0 Mon Sep 17 00:00:00 2001 From: "Zheng, Lei" Date: Sat, 3 Feb 2024 09:22:28 +0800 Subject: [PATCH] App: fix PropertyPythonObject persistence backward compatibility Related #10460 --- src/App/PropertyPythonObject.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/App/PropertyPythonObject.cpp b/src/App/PropertyPythonObject.cpp index 6ed1cf4abd..63ac957b10 100644 --- a/src/App/PropertyPythonObject.cpp +++ b/src/App/PropertyPythonObject.cpp @@ -92,14 +92,17 @@ std::string PropertyPythonObject::toString() const Py::Callable state(this->object.getAttr("dumps")); dump = state.apply(args); } -#if PY_VERSION_HEX < 0x030b0000 // support add-ons that use the old method names - else if (this->object.hasAttr("__getstate__")) { + else if (this->object.hasAttr("__getstate__") +#if PY_VERSION_HEX >= 0x030b0000 + && this->object.getAttr("__getstate__").hasAttr("__func__") +#endif + ) + { Py::Tuple args; Py::Callable state(this->object.getAttr("__getstate__")); dump = state.apply(args); } -#endif else if (this->object.hasAttr("__dict__")) { dump = this->object.getAttr("__dict__"); } @@ -143,15 +146,18 @@ void PropertyPythonObject::fromString(const std::string& repr) Py::Callable state(this->object.getAttr("loads")); state.apply(args); } -#if PY_VERSION_HEX < 0x030b0000 // support add-ons that use the old method names - else if (this->object.hasAttr("__setstate__")) { + else if (this->object.hasAttr("__setstate__") +#if PY_VERSION_HEX >= 0x030b0000 + && this->object.getAttr("__setstate__").hasAttr("__func__") +#endif + ) + { Py::Tuple args(1); args.setItem(0, res); Py::Callable state(this->object.getAttr("__setstate__")); state.apply(args); } -#endif else if (this->object.hasAttr("__dict__")) { if (!res.isNone()) { this->object.setAttr("__dict__", res);