In the previous version, when I would like to do some changes in the prepend text of a code. I would load the code and then use the set_prepend_text() method. In the version (AiiDA v2.6.1) this method is deprecated and does not let me do any change. Is there a way to change the prepend text without having to redefine a new code?
I think it is rather because your code is stored in the database and AiiDA does not allow you to change this property after is stored. See this code
from aiida.orm import InstalledCode, load_computer
from aiida import load_profile
load_profile()
code = InstalledCode(
computer=load_computer("localhost"),
filepath_executable="/bin/bash",
label="mycustom_code",
default_calc_job_plugin="core.arithmetic.add",
prepend_text="init"
)
print("code.prepend_text", code.prepend_text)
code.set_prepend_text("hello")
# recommended way now is to do it like this
# code.prepend_text = "hello"
# but this is not the problem
print("code.prepend_text", code.prepend_text)
print("\n\n")
code.store() # stored in database
try:
code.set_prepend_text("hello")
except Exception as err:
print("Error:\n", err) # Inmutable error
# same error also for this
try:
code.prepend_text = "hello"
except Exception as err:
print("Same error:\n", err) # Inmutable error
with output
code.prepend_text init
/Users/alexgo/miniconda3/lib/python3.12/site-packages/aiida/orm/nodes/data/code/legacy.py:405: AiidaDeprecationWarning: `Code.set_prepend_text` method is deprecated, use the `prepend_text` property instead. (this will be removed in v3)
warn_deprecation(
code.prepend_text hello
Error:
the attributes of a stored entity are immutable
Same error:
the attributes of a stored entity are immutable
The only solution I see is to create a new code. You can use code.clone
mynew_code = code.clone()
mynew_code.prepend_text = "my prepend text"