Deep python bug. Changing an object via propertyLink may touch unnecessary stuff [fix proposed]

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: Deep python bug. Changing an object via propertyLink may touch unnecessary stuff [reopened]

Post by DeepSOIC »

I propose a fix!
https://github.com/FreeCAD/FreeCAD/pull/698
EDIT: my progress over there smashed into a brick wall caused by this bug (a document being an attribute of itself caused infinite recursion). I couldn't move forward without fixing it.
wmayer
Founder
Posts: 20241
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Deep python bug. Changing an object via propertyLink may touch unnecessary stuff [fix proposed]

Post by wmayer »

Here is an example to force the DAG error:

Code: Select all

App.newDocument()
sketch=App.ActiveDocument.addObject("Sketcher::SketchObject","Sketch")
extrude=App.ActiveDocument.addObject("Part::Extrusion","Extrude")
extrude.Base=sketch

from BOPTools import SplitFeatures 
slice=SplitFeatures.makeSlice("Slice")
slice.Base=extrude

from CompoundTools import CompoundFilter
filter=CompoundFilter.makeCompoundFilter("CompoundFilter")
filter.Base=slice

extrude.Label = "test"
And here is an example that causes a stack overflow:

Code: Select all

class ViewProvider:
  def __init__(self, vobj):
    vobj.Proxy=self

  def attach(self, vobj):
    self.ViewObject = vobj
    self.Object = vobj.Object

  def claimChildren(self):
    children = [self.Object.Base]
    return children

doc=App.newDocument()
obj=doc.addObject("Part::FeaturePython", "Sketch")
obj.addProperty("App::PropertyLink","Base")
ViewProvider(obj.ViewObject)

ext=doc.addObject("Part::FeaturePython", "Extrude")
ext.addProperty("App::PropertyLink","Base").Base=obj
ViewProvider(ext.ViewObject)

sli=doc.addObject("Part::FeaturePython", "Slice")
sli.addProperty("App::PropertyLink","Base").Base=ext
ViewProvider(sli.ViewObject)

com=doc.addObject("Part::FeaturePython", "CompoundFilter")
com.addProperty("App::PropertyLink", "Base").Base=sli
ViewProvider(com.ViewObject)
doc.recompute()

ext.Label="test"
wmayer
Founder
Posts: 20241
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Deep python bug. Changing an object via propertyLink may touch unnecessary stuff [fix proposed]

Post by wmayer »

Here is an example showing the DAG problem with only low-level feature classes:

Code: Select all

class ViewProvider:
  def __init__(self, vobj):
    vobj.Proxy=self

  def attach(self, vobj):
    self.ViewObject = vobj
    self.Object = vobj.Object

  def claimChildren(self):
    children = [self.Object.Link]
    return children

doc=App.newDocument()
obj=doc.addObject("App::FeaturePython", "Sketch")
obj.addProperty("App::PropertyLink","Link")
ViewProvider(obj.ViewObject)

ext=doc.addObject("App::FeatureTest", "Extrude")
ext.Link=obj

sli=doc.addObject("App::FeaturePython", "Slice")
sli.addProperty("App::PropertyLink","Link").Link=ext
ViewProvider(sli.ViewObject)

com=doc.addObject("App::FeaturePython", "CompoundFilter")
com.addProperty("App::PropertyLink", "Link").Link=sli
ViewProvider(com.ViewObject)

ext.Label="test"
wmayer
Founder
Posts: 20241
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Deep python bug. Changing an object via propertyLink may touch unnecessary stuff [fix proposed]

Post by wmayer »

git commit a2dd176bc fixes the actual problem. The issue comes up when an object has an attribute e.g. Base and by its parent object it is also known as Base. Since both information are saved in a single dictionary it can happen that parent object & object attribute are mixed up and due to the chain of notification a cyclic dependency is created.
Post Reply