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

Toml Version 0.10.1 regression as compared to 0.10.0: ValueError: Circular reference detected #299

Closed
JoeJasinski opened this issue May 29, 2020 · 3 comments

Comments

@JoeJasinski
Copy link

Hi all,
This dictionary below cannot be serialized to toml in 0.10.1, but it was able to be serialized in 0.10.0. (This is a simplified output that was generated by the https://github.com/jupyterhub/traefik-proxy project). According to the commit history, some changes went in place to raise the Circular reference detected. However, I'm not sure how the below dict would be considered a circular reference, and considering it worked with 0.10.0, it seems odd that it would be considered one now. I'm able to serialize with yaml without issue, for example.

{'backends': {'backend__2Fdsadmin_2Fhub_2F': {},
                  'backend__2Fdsadmin_2Fhub_2Fuser_2Fjoe_2Ej_40example_2Ecom_2F': {},
                  'backend__2Fdsadmin_2Fhub_2Fuser_2Fkrombo_2Emichael_40example_2Ecom_2F': {},
  },
 'frontends': {'frontend__2Fdsadmin_2Fhub_2F': {'routes': {'test': {}}},
               'frontend__2Fdsadmin_2Fhub_2Fuser_2Fjoe_2Ej_40example_2Ecom_2F': {'routes': {'test': {}}},
               'frontend__2Fdsadmin_2Fhub_2Fuser_2Fkrombo_2Emichael_40example_2Ecom_2F': {'routes': {'test': {}}},
}}

Steps to reproduce with toml==0.10.1

$ docker run -it python:3.8.2 bash
root@f89cdc41e3af:/# pip install toml==0.10.1
Collecting toml==0.10.1
  Downloading toml-0.10.1-py2.py3-none-any.whl (19 kB)
Installing collected packages: toml
Successfully installed toml-0.10.1
WARNING: You are using pip version 20.0.2; however, version 20.1.1 is available.
You should consider upgrading via the '/usr/local/bin/python -m pip install --upgrade pip' command.
root@f89cdc41e3af:/# pip install pyyaml==5.3.1 # for comparrision
Collecting pyyaml==5.3.1
  Downloading PyYAML-5.3.1.tar.gz (269 kB)
     |████████████████████████████████| 269 kB 3.1 MB/s 
Building wheels for collected packages: pyyaml
  Building wheel for pyyaml (setup.py) ... done
  Created wheel for pyyaml: filename=PyYAML-5.3.1-cp38-cp38-linux_x86_64.whl size=572452 sha256=38dad2849fb02e58540047a6018b3125733f050fafbe323d39546b7fb4bd3fb5
  Stored in directory: /root/.cache/pip/wheels/13/90/db/290ab3a34f2ef0b5a0f89235dc2d40fea83e77de84ed2dc05c
Successfully built pyyaml
Installing collected packages: pyyaml
Successfully installed pyyaml-5.3.1
WARNING: You are using pip version 20.0.2; however, version 20.1.1 is available.
You should consider upgrading via the '/usr/local/bin/python -m pip install --upgrade pip' command.
root@f89cdc41e3af:/# 
root@f89cdc41e3af:/# python
Python 3.8.2 (default, Feb 26 2020, 14:58:38) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 
>>> import yaml
>>> import toml
>>> d = {'backends': {'backend__2Fdsadmin_2Fhub_2F': {},
...                   'backend__2Fdsadmin_2Fhub_2Fuser_2Fjoe_2Ej_40example_2Ecom_2F': {},
...                   'backend__2Fdsadmin_2Fhub_2Fuser_2Fkrombo_2Emichael_40example_2Ecom_2F': {},
...   },
...  'frontends': {'frontend__2Fdsadmin_2Fhub_2F': {'routes': {'test': {}}},
...                'frontend__2Fdsadmin_2Fhub_2Fuser_2Fjoe_2Ej_40example_2Ecom_2F': {'routes': {'test': {}}},
...                'frontend__2Fdsadmin_2Fhub_2Fuser_2Fkrombo_2Emichael_40example_2Ecom_2F': {'routes': {'test': {}}},
... }}
>>> 
>>> print(yaml.dump(d))
backends:
  backend__2Fdsadmin_2Fhub_2F: {}
  backend__2Fdsadmin_2Fhub_2Fuser_2Fjoe_2Ej_40example_2Ecom_2F: {}
  backend__2Fdsadmin_2Fhub_2Fuser_2Fkrombo_2Emichael_40example_2Ecom_2F: {}
frontends:
  frontend__2Fdsadmin_2Fhub_2F:
    routes:
      test: {}
  frontend__2Fdsadmin_2Fhub_2Fuser_2Fjoe_2Ej_40example_2Ecom_2F:
    routes:
      test: {}
  frontend__2Fdsadmin_2Fhub_2Fuser_2Fkrombo_2Emichael_40example_2Ecom_2F:
    routes:
      test: {}

>>> toml.dumps(d)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.8/site-packages/toml/encoder.py", line 67, in dumps
    raise ValueError("Circular reference detected")
ValueError: Circular reference detected

Steps to show successful serialization with toml==0.10.0

$ docker run -it python:3.8.2 bash
root@9f40631841db:/# pip install toml==0.10.0
Collecting toml==0.10.0
  Downloading toml-0.10.0-py2.py3-none-any.whl (25 kB)
Installing collected packages: toml
Successfully installed toml-0.10.0
WARNING: You are using pip version 20.0.2; however, version 20.1.1 is available.
You should consider upgrading via the '/usr/local/bin/python -m pip install --upgrade pip' command.
root@9f40631841db:/# 
root@9f40631841db:/# python
Python 3.8.2 (default, Feb 26 2020, 14:58:38) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 
>>> import toml
>>> d = {'backends': {'backend__2Fdsadmin_2Fhub_2F': {},
...                   'backend__2Fdsadmin_2Fhub_2Fuser_2Fjoe_2Ej_40example_2Ecom_2F': {},
...                   'backend__2Fdsadmin_2Fhub_2Fuser_2Fkrombo_2Emichael_40example_2Ecom_2F': {},
...   },
...  'frontends': {'frontend__2Fdsadmin_2Fhub_2F': {'routes': {'test': {}}},
...                'frontend__2Fdsadmin_2Fhub_2Fuser_2Fjoe_2Ej_40example_2Ecom_2F': {'routes': {'test': {}}},
...                'frontend__2Fdsadmin_2Fhub_2Fuser_2Fkrombo_2Emichael_40example_2Ecom_2F': {'routes': {'test': {}}},
... }}
>>> 
>>> toml.dumps(d)
'[backends.backend__2Fdsadmin_2Fhub_2F]\n\n[backends.backend__2Fdsadmin_2Fhub_2Fuser_2Fjoe_2Ej_40example_2Ecom_2F]\n\n[backends.backend__2Fdsadmin_2Fhub_2Fuser_2Fkrombo_2Emichael_40example_2Ecom_2F]\n\n[frontends.frontend__2Fdsadmin_2Fhub_2F.routes.test]\n\n[frontends.frontend__2Fdsadmin_2Fhub_2Fuser_2Fjoe_2Ej_40example_2Ecom_2F.routes.test]\n\n[frontends.frontend__2Fdsadmin_2Fhub_2Fuser_2Fkrombo_2Emichael_40example_2Ecom_2F.routes.test]\n'
>>> 

@Edward-Knight
Copy link

Seems to be a duplicate of #295 - I believe it's caused by the empty dictionary

@Edward-Knight
Copy link

Can confirm is fixed by 9be6458, just tried your example myself on master

@uiri
Copy link
Owner

uiri commented Aug 22, 2020

Duplicate of #295

@uiri uiri marked this as a duplicate of #295 Aug 22, 2020
@uiri uiri closed this as completed Aug 22, 2020
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