Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A subclass of str cannot be serialized #251

Closed
j5255089 opened this issue Apr 24, 2022 · 1 comment
Closed

A subclass of str cannot be serialized #251

j5255089 opened this issue Apr 24, 2022 · 1 comment

Comments

@j5255089
Copy link

[type(i) for i in a]
Out[109]:
[sqlalchemy.sql.elements.quoted_name,
sqlalchemy.sql.elements.quoted_name,
sqlalchemy.sql.elements.quoted_name,
sqlalchemy.sql.elements.quoted_name,
sqlalchemy.sql.elements.quoted_name,
sqlalchemy.sql.elements.quoted_name]
a
Out[110]:
{'id': 339,
'manualId': 'n_lje',
'name': '年度_累积额',
'description': '年度累计额',
'envs': '',
'rule_type': ''}
ujson.dumps(a)
Out[111]: '{"id":339,"manualId":"n_lje","name":"\u5e74\u5ea6_\u7d2f\u79ef\u989d","description":"\u5e74\u5ea6\u7d2f\u8ba1\u989d","envs":"","rule_type":""}'
orjson.dumps(a)
Traceback (most recent call last):
File "C:\Program Files\Python38\Lib\site-packages\IPython\core\interactiveshell.py", line 3457, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "", line 1, in
orjson.dumps(a)
TypeError: Dict key must be str
json.dumps(a)
Out[113]: '{"id": 339, "manualId": "n_lje", "name": "\u5e74\u5ea6_\u7d2f\u79ef\u989d", "description": "\u5e74\u5ea6\u7d2f\u8ba1\u989d", "envs": "", "rule_type": ""}'
issubclass(quoted_name, str)
Out[114]: True

@edgarrmondragon
Copy link

Bump, facing a similar issue with sqlalchemy.sql.elements.quoted_name. I don't know one iota of Rust, but I wonder if this check here:

if unlikely!(unsafe { ob_type!(key) != STR_TYPE }) {

could be made so it checks if the key is a subclass of string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants