Script.data_exists() not working after transaction

Hello, whenerver I run the functions script.data_exitst(“example”), script.store_data(“example”, dataClass) or script.load_data(“example”) after a transaction, I get below error.

To reproduce this issue you can simply run bellow code:

from pyrevit import revit

49 with revit.Transaction("test"):
50         pass
51 print script.data_exists("example")

If you run this code without a transaction or in the transaction, there is no issue.
For my use case, it is not possible to run these functions inside a transaction.

**IronPython Traceback:**
Traceback (most recent call last):
File "C:\Users\Wietse_d\Documents\Github\WDE-addins\WYC-addins.extension\WYC.tab\Dev.panel\Test.pushbutton\script.py", line 51, in <module>
File "C:\Users\Wietse_d\AppData\Roaming\pyRevit\pyRevit\master\pyrevitlib\pyrevit\script.py", line 743, in data_exists
File "C:\Users\Wietse_d\AppData\Roaming\pyRevit\pyRevit\master\pyrevitlib\pyrevit\script.py", line 315, in get_document_data_file
File "C:\Users\Wietse_d\AppData\Roaming\pyRevit\pyRevit\master\pyrevitlib\pyrevit\revit\db\__init__.py", line 297, in filename
File "C:\Users\Wietse_d\AppData\Roaming\pyRevit\pyRevit\master\pyrevitlib\pyrevit\revit\db\__init__.py", line 293, in path
AttributeError: 'NoneType' object has no attribute 'PathName'

**Script Executor Traceback:**
System.MissingMemberException: 'NoneType' object has no attribute 'PathName'
at Microsoft.Scripting.Interpreter.ThrowInstruction.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.LightLambda.Run3[T0,T1,T2,TRet](T0 arg0, T1 arg1, T2 arg2)
at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
at IronPython.Compiler.Ast.DynamicGetMemberExpression.GetMemberInstruction.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1)
at IronPython.Runtime.PythonProperty.__get__(CodeContext context, Object instance, Object owner)
at IronPython.Runtime.PythonProperty.TryGetValue(CodeContext context, Object instance, PythonType owner, Object& value)
at IronPython.Runtime.Types.GetMemberDelegates.SlotOnly(CallSite site, Object self, CodeContext context)
at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
at IronPython.Compiler.Ast.DynamicGetMemberExpression.GetMemberInstruction.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1)
at IronPython.Runtime.PythonProperty.__get__(CodeContext context, Object instance, Object owner)
at IronPython.Runtime.PythonProperty.TryGetValue(CodeContext context, Object instance, PythonType owner, Object& value)
at IronPython.Runtime.Types.GetMemberDelegates.SlotOnly(CallSite site, Object self, CodeContext context)
at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
at IronPython.Compiler.Ast.DynamicGetMemberExpression.GetMemberInstruction.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.LightLambda.Run4[T0,T1,T2,T3,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3)
at IronPython.Compiler.PythonCallTargets.OriginalCallTarget3(PythonFunction function, Object arg0, Object arg1, Object arg2)
at Microsoft.Scripting.Interpreter.FuncCallInstruction`6.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.LightLambda.Run6[T0,T1,T2,T3,T4,T5,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5)
at System.Dynamic.UpdateDelegates.UpdateAndExecute5[T0,T1,T2,T3,T4,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4)
at Microsoft.Scripting.Interpreter.DynamicInstruction`6.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.LightLambda.Run3[T0,T1,T2,TRet](T0 arg0, T1 arg1, T2 arg2)
at System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2)
at Microsoft.Scripting.Interpreter.DynamicInstruction`4.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1)
at IronPython.Compiler.PythonScriptCode.RunWorker(CodeContext ctx)
at PyRevitLabs.PyRevit.Runtime.IronPythonEngine.Execute(ScriptRuntime& runtime)

Hi @baaswietse, I’m sorry you’re experiencing this issue…

Just to be sure: are you working on an existing document/project?

It seems that the ProjectInfo class loses the reference to the currently opened document, and so the PathName can’t be reached.

could you please tell us what does the following returns if you put it after the transaction?

from pyreivt import HOST_APP

print(HOST_APP.doc.PathName)

Hello, thank you for the response.
I am working on an active document, I tried it on a local model and on a cloud model, with the same issue.

Running your code gets me below output.
Autodesk Docs://Gent - Parking UZ/Gent DB UZ Parking.rvt

When I run the code after a transaction:

from pyrevit import HOST_APP, revit

with revit.Transaction("test transaction"):
    pass
print(HOST_APP.doc.PathName)

I get this output:

IronPython Traceback:
Traceback (most recent call last):
 File "C:\Users\Wietse_d\Documents\Github\WDE-addins\WYC-addins.extension\WYC.tab\Dev.panel\Test.pushbutton\script.py", line 53, in <module>
AttributeError: 'NoneType' object has no attribute 'PathName'


Script Executor Traceback:
System.MissingMemberException: 'NoneType' object has no attribute 'PathName'
 at Microsoft.Scripting.Interpreter.ThrowInstruction.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.LightLambda.Run3[T0,T1,T2,TRet](T0 arg0, T1 arg1, T2 arg2)
 at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
 at Microsoft.Scripting.Interpreter.DynamicInstruction`3.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1)
 at IronPython.Compiler.PythonScriptCode.RunWorker(CodeContext ctx)
 at PyRevitLabs.PyRevit.Runtime.IronPythonEngine.Execute(ScriptRuntime& runtime)

Hi, I’m afraid you discovered a bug!

@Jean-Marc it seems that somewhere, when exiting the transaction manager, the host application object loses the reference to the document, but I couldn’t fund out exactly where.

@baaswietse would you be so kind to open an issue on github linking this discussion and providing us all the details (follow the instruction on the issue template)? Thanks

I have made the bug report on Github: ProjectInfo class loses reference to the currently opened document after transaction is closed · Issue #2006 · eirannejad/pyRevit · GitHub

replied in the issue earlier,
@baaswietse
I tried it on my side with latest installers and engine 2711


from pyrevit import revit, script, HOST_APP 
script.store_data("example", "Hello World!", this_project=True) 
with revit.Transaction("test"): 
    pass 
print(script.data_exists("example")) 
print(script.load_data("example")) 
print(HOST_APP.doc.PathName)

It works just fine

Is your file saved?

Hello @Jean-Marc, after switching from 277 to 2711 and restarting my computer the issue persists…
I tried on a local saved file and a file hosted on ACC.

46    from pyrevit import revit, script, HOST_APP
47
48    script.store_data("example", "Hello World!", this_project=True)
49    with revit.Transaction("test"):
50        pass
51    print(script.data_exists("example"))
52    print(script.load_data("example"))
53    print(HOST_APP.doc.PathName)
IronPython Traceback:
Traceback (most recent call last):
 File "C:\Users\Wietse_d\Documents\Github\WDE-addins\WYC-addins.extension\WYC.tab\Dev.panel\Test.pushbutton\script.py", line 51, in <module>
 File "C:\Users\Wietse_d\AppData\Roaming\pyRevit\pyRevit\master\pyrevitlib\pyrevit\script.py", line 743, in data_exists
 File "C:\Users\Wietse_d\AppData\Roaming\pyRevit\pyRevit\master\pyrevitlib\pyrevit\script.py", line 315, in get_document_data_file
 File "C:\Users\Wietse_d\AppData\Roaming\pyRevit\pyRevit\master\pyrevitlib\pyrevit\revit\db\__init__.py", line 297, in filename
 File "C:\Users\Wietse_d\AppData\Roaming\pyRevit\pyRevit\master\pyrevitlib\pyrevit\revit\db\__init__.py", line 293, in path
AttributeError: 'NoneType' object has no attribute 'PathName'

Script Executor Traceback:
System.MissingMemberException: 'NoneType' object has no attribute 'PathName'
 at Microsoft.Scripting.Interpreter.ThrowInstruction.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.LightLambda.Run3[T0,T1,T2,TRet](T0 arg0, T1 arg1, T2 arg2)
 at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
 at IronPython.Runtime.Binding.PythonGetMemberBinder.FastPropertyGet`1.GetProperty(CallSite site, TSelfType target, CodeContext context)
 at IronPython.Compiler.Ast.DynamicGetMemberExpression.GetMemberInstruction.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1)
 at IronPython.Runtime.PythonProperty.__get__(CodeContext context, Object instance, Object owner)
 at IronPython.Runtime.PythonProperty.TryGetValue(CodeContext context, Object instance, PythonType owner, Object& value)
 at IronPython.Runtime.Types.GetMemberDelegates.SlotOnly(CallSite site, Object self, CodeContext context)
 at IronPython.Compiler.Ast.DynamicGetMemberExpression.GetMemberInstruction.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1)
 at IronPython.Runtime.PythonProperty.__get__(CodeContext context, Object instance, Object owner)
 at IronPython.Runtime.PythonProperty.TryGetValue(CodeContext context, Object instance, PythonType owner, Object& value)
 at IronPython.Runtime.Types.GetMemberDelegates.SlotOnly(CallSite site, Object self, CodeContext context)
 at IronPython.Compiler.Ast.DynamicGetMemberExpression.GetMemberInstruction.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.LightLambda.Run4[T0,T1,T2,T3,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3)
 at Microsoft.Scripting.Interpreter.FuncCallInstruction`6.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.LightLambda.Run6[T0,T1,T2,T3,T4,T5,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5)
 at System.Dynamic.UpdateDelegates.UpdateAndExecute5[T0,T1,T2,T3,T4,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4)
 at Microsoft.Scripting.Interpreter.DynamicInstruction`6.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.LightLambda.Run3[T0,T1,T2,TRet](T0 arg0, T1 arg1, T2 arg2)
 at System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2)
 at Microsoft.Scripting.Interpreter.DynamicInstruction`4.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1)
 at IronPython.Compiler.PythonScriptCode.RunWorker(CodeContext ctx)
 at PyRevitLabs.PyRevit.Runtime.IronPythonEngine.Execute(ScriptRuntime& runtime)

Here is my environment info:

C:\Users\Wietse_d>pyrevit env
==> Registered Clones (full git repos)
master | Branch: "master" | Version: "4.8.13.23182+2215:0027524" | Path: "C:\Users\Wietse_d\AppData\Roaming\pyRevit\pyRevit\master"
==> Registered Clones (deployed from archive/image)
==> Attachments
master | Product: "Autodesk Revit 2024" | Engine: DEFAULT (2711) | Path: "C:\Users\Wietse_d\AppData\Roaming\pyRevit\pyRevit\master"
master | Product: "Autodesk Revit 2023" | Engine: DEFAULT (2711) | Path: "C:\Users\Wietse_d\AppData\Roaming\pyRevit\pyRevit\master"
master | Product: "Autodesk Revit 2022" | Engine: DEFAULT (2711) | Path: "C:\Users\Wietse_d\AppData\Roaming\pyRevit\pyRevit\master"
master | Product: "Autodesk Revit 2021" | Engine: DEFAULT (2711) | Path: "C:\Users\Wietse_d\AppData\Roaming\pyRevit\pyRevit\master"
==> Installed Extensions
WYC-addins | Type: Unknown | Repo: "" | Installed: "C:\Users\Wietse_d\Documents\Github\WDE-addins\WYC-addins.extension"
==> Default Extension Search Path
C:\Users\Wietse_d\AppData\Roaming\pyRevit\Extensions
==> Extension Search Paths
C:\Users\Wietse_d\Documents\Github\WDE-addins
==> Extension Sources - Default
https://github.com/eirannejad/pyRevit/raw/master/extensions/extensions.json
==> Extension Sources - Additional
==> Installed Revits
Autodesk Revit 2024 | Version: 24.1.11.26 | Build: 20230911_1230(x64) | Language: 1033 | Path: "C:\Program Files\Autodesk\Revit 2024\"
Autodesk Revit 2023 | Version: 23.1.30.97 | Build: 20230828_1515(x64) | Language: 1033 | Path: "C:\Program Files\Autodesk\Revit 2023\"
Autodesk Revit 2022 | Version: 22.1.50.17 | Build: 20230915_1530(x64) | Language: 1033 | Path: "C:\Program Files\Autodesk\Revit 2022\"
Autodesk Revit 2021 | Version: 21.1.90.15 | Build: 20230907_1515(x64) | Language: 1033 | Path: "C:\Program Files\Autodesk\Revit 2021\"

@sanzoghenzo can you reproduce on your side?