01-23-2020 12:51 AM
Hi guys,
Inside Python callback call (ex. post_modification), I've always been using MAAPI read transactions (with maapi.single_read_trans) or sessions (maapi.Session). However I have recently discovered that we can get the same object definition by just calling maapi.cd (root, '/a/fancy/path/to/the/object'), which works basically the same for me.
The question is: are there any disadvantages of this approach of reading object config data? Or any scenarios (RFM?) this might not work well?
thanks,
robert
Solved! Go to Solution.
01-23-2020 08:47 AM
First, there is no real disadvantage to doing it like that, and if it works for you, keep at it.
But, using maapi.cd doesn’t really save you any work compared to starting a new transaction, because you need a socket and a transaction all the same. I am not entirely sure of what your code looks like, but if we look at a standard pre-modification method from the manual:
@Service.pre_modification def cb_pre_modification(self, tctx, op, kp, root, proplist): pass
Then that root object is a maagic.Node object, and already contains a transaction and everything. I think that what most people do in python is just use that root object and navigate using maagic.
In the end it is mostly a matter of style, and which APIs feel more comfortable to you. I just wanted to point out that the root object contains multitudes.
01-23-2020 08:47 AM
First, there is no real disadvantage to doing it like that, and if it works for you, keep at it.
But, using maapi.cd doesn’t really save you any work compared to starting a new transaction, because you need a socket and a transaction all the same. I am not entirely sure of what your code looks like, but if we look at a standard pre-modification method from the manual:
@Service.pre_modification def cb_pre_modification(self, tctx, op, kp, root, proplist): pass
Then that root object is a maagic.Node object, and already contains a transaction and everything. I think that what most people do in python is just use that root object and navigate using maagic.
In the end it is mostly a matter of style, and which APIs feel more comfortable to you. I just wanted to point out that the root object contains multitudes.
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide