Instant reverse python source can't handle metaclass inheritance

Hi there,

It appears the ‘Instant reverse’ → ‘python source’ function can’t handle classes that are created with the metaclass parameter.
A message is shown that instant reverse has been ‘completed with errors’ and none of these classes are part of the generated model.
Classes that inherit from these classes are also completely excluded.

I have looked into the vp.log file for an error message, but none is shown.

To reproduce the bug a python module containing this code can be given to the instant reverse tool;

class Test(metaclass=type):
    A = 1


class InheritedTest(Test):
    B = 2


class NoMeta:
    C = 3

We are actually using the sqlalchemy package in our project and using the declarative base mapping to map our python classes to the sqlalchemy orm.
This is done by inheriting classes that should be persisted from the sqlalchemy declarative base class.
Since the declarative base class is a metaclass, our complete orm model is missing when using this visual paradigm feature.

It would be wonderful if this piece of code could be successfully reversed:

from sqlalchemy.orm.decl_api import registry, DeclarativeMeta

sql_alchemy_registry = registry()

class SqlAlchemyBase(metaclass=DeclarativeMeta):
    
    registry = sql_alchemy_registry
    metadata = sql_alchemy_registry.metadata
    __abstract__ = True
    __init__ = sql_alchemy_registry.constructor

Thank you in advance for considering this report. I look forward to your response.

Hi eduard_hendriksen,

Thank you for your post. Your question has been forwarded to our team for further studying. When there is any news, I will share with you.

Best regards,
Jick Yeung

Hi eduard_hendriksen,

I am glad to inform you that the problem has been fixed. Please update to the latest patch build to obtain the fix. The steps can be found in the article below:

Should you have any questions, please feel free to let me know.

Best regards,
Jick Yeung

Thank you very much for the quick fix and update.

During testing of the new update, I found that the metaclass import is currently working as intended, so thanks very much for the fix.

I did, however, stumble upon another item that prevented a class from being reversed.
After some testing, I think the problem is the use of list comprehension during dict instantiation.

The smallest example I have causing this error is the following;

attributes = ["a", "b", "c"]
test_dict = {attr: index for index, attr in enumerate(attributes)}

The error message found in the vp.log is the following;
[message] java.lang.ClassCastException: class v.bdm.bm cannot be cast to class v.bdm.bj (v.bdm.bm and v.bdm.bj are in unnamed module of loader 'app')

And one example showcasing the class reversal not occurring when this error occurs;

from typing import Dict, Sequence


class Test(metaclass=type):
    def attribute_dict(self, attributes: Sequence[str]) -> Dict:
        return {attr_name: getattr(self, attr_name) for attr_name in attributes}

Thanks in advance for looking into this!

Hi eduard_hendriksen,

We are glad to know that the fix works. Thanks for your post. I have just asked our engineers to take a look at the new problem you described. Again, I will let you know when there is any news.

Best regards,
Jick Yeung

Hi eduard_hendriksen,

Problem fixed. You may update again to the latest patch build to get the fix. :slight_smile:

Best regards,
Jick Yeung

Hi Jick,

Thanks again for the quick fix!
I will get on it right away.

Best wishes,
Eduard

Hi Jick,

Unfortunately the fix doesn’t seem to have helped on my system.
Neither of the two examples I provided are currently functioning on my end.
Thanks again for being so responsive.

Best wishes,

Eduard

Hi Eduard,

Sorry about that. Let me check…

Best regards,
Jick Yeung

Hi Eduard,

I found that the previous build was not properly deployed. It should be working now. Please try again.

Best regards,
Jick Yeung