dashingsoft / pyarmor

A tool used to obfuscate python scripts, bind obfuscated scripts to fixed machine or expire obfuscated scripts.
http://pyarmor.dashingsoft.com
Other
3.46k stars 293 forks source link

[BUG] 添加`--enable-rft`之后,sqlalchemy的model声明失败 #1792

Closed kyle-kw closed 5 months ago

kyle-kw commented 5 months ago

Please read this first before report any issue https://pyarmor.readthedocs.io/en/latest/questions.html

If this issue has been documented and there is solution in FAQ, it will be marked as documented and be closed it immediately.

Do not ask questions here but in discussions, it will be closed immediately.

A good report should have

Please also provide necessary log (but not full log), for example, the whole command options pyarmor gen and first 4 logs in the console, paste the text directly, DO NOT paste IMAGE


test.py

from sqlalchemy import Column, Index, Integer, String
from sqlalchemy.ext.declarative import declarative_base
# sqlalchemy==1.4.52
Base = declarative_base()
metadata = Base.metadata

class ChannelKey(Base):
    __tablename__ = '01_channel_keys'
    __table_args__ = (
        Index('idx_channel', 'key_type', unique=True),
    )

    record_pk = Column(Integer, primary_key=True, autoincrement=True)
    key_type = Column(String(100), nullable=False)

if __name__ == '__main__':
    print(ChannelKey.__tablename__)
$ pyarmor gen --enable-rft test.py
INFO     Python 3.9.19
INFO     Pyarmor 8.5.8 (group), 006279, jfh
INFO     Platform linux.x86_64

$python test.py
<frozen test2>:6: MovedIn20Warning: Deprecated API features detected! These feature(s) are not compatible with SQLAlchemy 2.0. To prevent incompatible upgrades prior to updating applications, ensure requirements files are pinned to "sqlalchemy<2.0". Set environment variable SQLALCHEMY_WARN_20=1 to show all deprecation warnings.  Set environment variable SQLALCHEMY_SILENCE_UBER_WARNING=1 to silence this message. (Background on SQLAlchemy 2.0 at: https://sqlalche.me/e/b8d9)
Traceback (most recent call last):
  File "<frozen __main__>", line 3, in <module>
  File "<frozen test2>", line 10, in <module>
  File "/home/ubuntu/miniconda3/envs/one-key/lib/python3.9/site-packages/sqlalchemy/orm/decl_api.py", line 76, in __init__
    _as_declarative(reg, cls, dict_)
  File "/home/ubuntu/miniconda3/envs/one-key/lib/python3.9/site-packages/sqlalchemy/orm/decl_base.py", line 126, in _as_declarative
    return _MapperConfig.setup_mapping(registry, cls, dict_, None, {})
  File "/home/ubuntu/miniconda3/envs/one-key/lib/python3.9/site-packages/sqlalchemy/orm/decl_base.py", line 183, in setup_mapping
    return cfg_cls(registry, cls_, dict_, table, mapper_kw)
  File "/home/ubuntu/miniconda3/envs/one-key/lib/python3.9/site-packages/sqlalchemy/orm/decl_base.py", line 331, in __init__
    self._setup_table(table)
  File "/home/ubuntu/miniconda3/envs/one-key/lib/python3.9/site-packages/sqlalchemy/orm/decl_base.py", line 854, in _setup_table
    table_cls(
  File "<string>", line 2, in __new__
  File "/home/ubuntu/miniconda3/envs/one-key/lib/python3.9/site-packages/sqlalchemy/util/deprecations.py", line 375, in warned
    return fn(*args, **kwargs)
  File "/home/ubuntu/miniconda3/envs/one-key/lib/python3.9/site-packages/sqlalchemy/sql/schema.py", line 619, in __new__
    metadata._remove_table(name, schema)
  File "/home/ubuntu/miniconda3/envs/one-key/lib/python3.9/site-packages/sqlalchemy/util/langhelpers.py", line 70, in __exit__
    compat.raise_(
  File "/home/ubuntu/miniconda3/envs/one-key/lib/python3.9/site-packages/sqlalchemy/util/compat.py", line 211, in raise_
    raise exception
  File "/home/ubuntu/miniconda3/envs/one-key/lib/python3.9/site-packages/sqlalchemy/sql/schema.py", line 614, in __new__
    table._init(name, metadata, *args, **kw)
  File "/home/ubuntu/miniconda3/envs/one-key/lib/python3.9/site-packages/sqlalchemy/sql/schema.py", line 700, in _init
    self._init_items(
  File "/home/ubuntu/miniconda3/envs/one-key/lib/python3.9/site-packages/sqlalchemy/sql/schema.py", line 144, in _init_items
    spwd(self, **kw)
  File "/home/ubuntu/miniconda3/envs/one-key/lib/python3.9/site-packages/sqlalchemy/sql/base.py", line 1047, in _set_parent_with_dispatch
    self._set_parent(parent, **kw)
  File "/home/ubuntu/miniconda3/envs/one-key/lib/python3.9/site-packages/sqlalchemy/sql/schema.py", line 4313, in _set_parent
    ColumnCollectionMixin._set_parent(self, table)
  File "/home/ubuntu/miniconda3/envs/one-key/lib/python3.9/site-packages/sqlalchemy/sql/schema.py", line 3433, in _set_parent
    for col in self._col_expressions(table):
  File "/home/ubuntu/miniconda3/envs/one-key/lib/python3.9/site-packages/sqlalchemy/sql/schema.py", line 3427, in _col_expressions
    return [
  File "/home/ubuntu/miniconda3/envs/one-key/lib/python3.9/site-packages/sqlalchemy/sql/schema.py", line 3428, in <listcomp>
    table.c[col] if isinstance(col, util.string_types) else col
  File "/home/ubuntu/miniconda3/envs/one-key/lib/python3.9/site-packages/sqlalchemy/sql/base.py", line 1214, in __getitem__
    return self._index[key]
KeyError: 'key_type'

In order to save time for both of us, if the bug report is not clear or missing necessary information, it will be marked as invalid and be closed immediately.

jondy commented 5 months ago

请参考文档 https://pyarmor.readthedocs.io/zh/latest/topic/rftmode.html

不要修改字段的名称,如果表的字段名称都修改了,需要数据库做相应的修改。

另外,报告问题的时候请删除不必要的内容,提供了一个清晰的报告

kyle-kw commented 5 months ago

好的,感谢

Blue-FatMan commented 2 months ago

你好,请问这个问题你解决了吗,我也遇到了,Base = declarative_base()这行代码经过加密之后,就无法运行了,也不获取不到报错信息,不知道啥原因