Closed pablo-campillo closed 1 year ago
Hi @pablo-campillo ,
Thanks for the ticket and the use-case! I think you found a nasty bug here, I can see from the serialized json that something is wrong in the computed href
. I'll try to fix it asap. I suspect a regression over a not well covered aspect of the json serialization. I suppose XMI doesn't have this regression.
Thanks again, I will fix that very soon!
Hi @pablo-campillo
Thanks again for the use-case and the issue. I fixed it on develop
, I cannot believe I didn't see it before, and I think I did because there was another bug in the JSON deserialization. Both bugs were hidding each others. Bottom line, I will improve my test set to catch well this case.
@aranega , Thanks to you!
Hi @pablo-campillo ,
Thanks for the report! I tried your use-case, but I cannot reproduce the problem on my side :grimacing:, everything is going just fine... For the execution of the code, I'm on the develop
branch with Python 3.10. What version of Python are you using ? The error would look like a loose of sync between the dynamic and static part of your metamodel, but I'm unsure how this could happen (could it be some tests that are loading metamodels two times or something like that?)
Hi @aranega,
I removed the issue because the problem was solved, I think I was loading the metamodel two times or something like that.
Now, I found a problem, when I deserialize a model instead of get instances of object generated static by pyecoregen I got EProxy objects, please, do you know why?
Thank you very much!
I'm glad this issue went away :)
Regarding the proxies, yes, everytime you deserialize models that are split into different resources, PyEcore puts a proxy to reference the external object. EMF does the same, but it has a mechanism that then transfers the real instance and reconnect things, destroying proxies. In PyEcore, the proxies stays, but acts like a transparent proxy, meaning that you can handle it as a normal instance and it will resolve the proxy on it's own when you access any feature of the object (loading the external resource automatically if this resource has not been loaded before). To avoid this, I should slightly change the way resources are deserialized by checking first if the external resource owning the object is already loaded in the resource set and resolve it from there. I think there is not so much work on that, but perhaps there is corner cases to deal with that. This joins a little bit what I can do to deal with #120 .
Ok, I understand. The problem is that isinstance(obj, Class) does not work, right?
It should work if the proxy can be resolved meaning if the external resource can be loaded (if it wasn't in the first place), EClass
and special metaclass redefine __instancecheck__
and other dunder methods. I have this behavior on my side:
from pyecore.ecore import EClass, EProxy
A = EClass('A')
instance = A()
proxy = EProxy(wrapped=instance)
assert isinstance(instance, A)
assert isinstance(proxy, A)
I want to split the model in several files. However, when I try to join the models, attributes that are references to an external resource are None.
My toy example (all files attached at files.zip):
Code:
The test:
The content of the serialized files:
The error:
files.zip