App: fix failure to detect cyclic dependencies on expressions

See also forum thread: https://forum.freecadweb.org/viewtopic.php?f=3&t=74331
This commit is contained in:
wmayer
2023-01-02 16:36:10 +01:00
parent d60f2e291f
commit 9efac962ac
2 changed files with 7 additions and 1 deletions

View File

@@ -1725,7 +1725,7 @@ Py::Object ObjectIdentifier::access(const ResolveResults &result,
else if(lastObj) {
const char *attr = components[idx].getName().c_str();
auto prop = lastObj->getPropertyByName(attr);
if(!prop && pyobj.hasAttr(attr))
if(!prop && !pyobj.hasAttr(attr))
attr = nullptr;
setPropDep(lastObj,prop,attr);
lastObj = nullptr;

View File

@@ -1632,6 +1632,12 @@ class DocumentExpressionCases(unittest.TestCase):
FreeCAD.closeDocument(self.Doc.Name)
self.Doc = FreeCAD.openDocument(SaveName)
def testCyclicDependencyOnPlacement(self):
obj = self.Doc.addObject("App::FeaturePython","Python")
obj.addProperty("App::PropertyPlacement", "Placement")
obj.setExpression('.Placement.Base.x', '.Placement.Base.y + 10mm')
with self.assertRaises(RuntimeError):
obj.setExpression('.Placement.Base.y', '.Placement.Base.x + 10mm')
def tearDown(self):
#closing doc