title: How to solve circular reference detected
body: <p>I need to convert json into toml format.</p>
  <p>When I run the following code, it returns with an error.</p>
  <pre><code>import toml
  
  toml_config = toml.dumps(data)
  </code></pre>
  <p>where <code>data</code> is:</p>
  <pre class="lang-json prettyprint-override"><code>{&quot;general&quot;:{&quot;log_level&quot;:{&quot;value&quot;:&quot;4&quot;,&quot;editable&quot;:&quot;true&quot;,&quot;description&quot;:&quot;debug=5, info=4, warning=3, error=2, fatal=1, panic=0&quot;},&quot;log_to_syslog&quot;:{&quot;value&quot;:&quot;false&quot;,&quot;editable&quot;:&quot;true&quot;,&quot;description&quot;:&quot;When set to true, log messages are being written to syslog.&quot;}},&quot;postgresql&quot;:{&quot;dsn&quot;:&quot;true&quot;,&quot;postgres://localhost/chirpstack_ns?sslmode\n\n# Automatically apply database migrations.\n#\n# It is possible to apply the database-migrations by hand\n# (see https://github.com/brocaar/chirpstack-network-server/tree/master/migrations)\n# or let ChirpStack Application Server migrate to the latest state automatically, by using\n# this setting. Make sure that you always make a backup when upgrading ChirpStack\n# Application Server and / or applying migrations.\nautomigratemax_open_connections&quot;:0,&quot;max_idle_connections&quot;:2},&quot;redis&quot;:{&quot;servers&quot;:[&quot;localhost:6379&quot;],&quot;password&quot;:&quot;&quot;,&quot;database&quot;:0,&quot;cluster&quot;:&quot;false&quot;,&quot;master_name&quot;:&quot;&quot;,&quot;pool_size&quot;:0},&quot;network_server&quot;:{&quot;net_id&quot;:&quot;000000&quot;,&quot;deduplication_delay&quot;:&quot;200ms&quot;,&quot;device_session_ttl&quot;:&quot;744h0m0s&quot;,&quot;get_downlink_data_delay&quot;:{&quot;value&quot;:&quot;100ms&quot;,&quot;editable&quot;:&quot;true&quot;},&quot;band&quot;:{&quot;name&quot;:&quot;EU868&quot;,&quot;uplink_dwell_time_400ms&quot;:&quot;false&quot;,&quot;downlink_dwell_time_400ms&quot;:&quot;false&quot;,&quot;uplink_max_eirp&quot;:-1,&quot;repeater_compatible&quot;:&quot;false&quot;},&quot;network_settings&quot;:{&quot;installation_margin&quot;:10,&quot;rx_window&quot;:0,&quot;rx1_delay&quot;:1,&quot;rx1_dr_offset&quot;:0,&quot;rx2_dr&quot;:-1,&quot;rx2_frequency&quot;:-1,&quot;rx2_prefer_on_rx1_dr_lt&quot;:0,&quot;rx2_prefer_on_link_budget&quot;:&quot;false&quot;,&quot;gateway_prefer_min_margin&quot;:10,&quot;downlink_tx_power&quot;:-1,&quot;disable_mac_commands&quot;:&quot;false&quot;,&quot;disable_adr&quot;:&quot;false&quot;,&quot;max_mac_command_error_count&quot;:3,&quot;enabled_uplink_channels&quot;:[],&quot;class_b&quot;:{&quot;ping_slot_dr&quot;:0,&quot;ping_slot_frequency&quot;:0},&quot;rejoin_request&quot;:{&quot;enabled&quot;:&quot;false&quot;,&quot;max_count_n&quot;:0,&quot;max_time_n&quot;:0}},&quot;scheduler&quot;:{&quot;scheduler_interval&quot;:&quot;1s&quot;,&quot;class_c&quot;:{&quot;downlink_lock_duration&quot;:&quot;2s&quot;,&quot;multicast_gateway_delay&quot;:&quot;2s&quot;}},&quot;api&quot;:{&quot;bind&quot;:&quot;0.0.0.0:8000&quot;,&quot;ca_cert&quot;:&quot;&quot;,&quot;tls_cert&quot;:&quot;&quot;,&quot;tls_key&quot;:&quot;&quot;},&quot;gateway&quot;:{&quot;ca_cert&quot;:&quot;&quot;,&quot;ca_key&quot;:&quot;&quot;,&quot;client_cert_lifetime&quot;:&quot;8760h0m0s&quot;,&quot;backend&quot;:{&quot;type&quot;:&quot;mqtt&quot;,&quot;multi_downlink_feature&quot;:&quot;hybrid&quot;,&quot;mqtt&quot;:{&quot;event_topic&quot;:&quot;gateway/+/event/+&quot;,&quot;command_topic_template&quot;:&quot;gateway/{{ .GatewayID }}/command/{{ .CommandType }}&quot;,&quot;server&quot;:&quot;tcp://localhost:1883&quot;,&quot;username&quot;:&quot;&quot;,&quot;password&quot;:&quot;&quot;,&quot;max_reconnect_interval&quot;:&quot;1m0s&quot;,&quot;qos&quot;:0,&quot;clean_session&quot;:&quot;true&quot;,&quot;client_id&quot;:&quot;&quot;,&quot;ca_cert&quot;:&quot;&quot;,&quot;tls_cert&quot;:&quot;&quot;,&quot;tls_key&quot;:&quot;&quot;},&quot;amqp&quot;:{&quot;url&quot;:&quot;amqp://guest:guest@localhost:5672&quot;,&quot;event_queue_name&quot;:&quot;gateway-events&quot;,&quot;event_routing_key&quot;:&quot;gateway.*.event.*&quot;,&quot;command_routing_key_template&quot;:&quot;gateway.{{ .GatewayID }}.command.{{ .CommandType }}&quot;},&quot;gcp_pub_sub&quot;:{&quot;credentials_file&quot;:&quot;&quot;,&quot;project_id&quot;:&quot;&quot;,&quot;uplink_topic_name&quot;:&quot;&quot;,&quot;downlink_topic_name&quot;:&quot;&quot;,&quot;uplink_retention_duration&quot;:&quot;24h0m0s&quot;},&quot;azure_iot_hub&quot;:{&quot;events_connection_string&quot;:{&quot;value&quot;:&quot;&quot;,&quot;editable&quot;:&quot;true&quot;,&quot;description&quot;:&quot;This connection string must point to the Service Bus Queue to which the IoT Hub is forwarding the (uplink) gateway events.&quot;},&quot;commands_connection_string&quot;:{&quot;value&quot;:&quot;&quot;,&quot;editable&quot;:&quot;true&quot;,&quot;description&quot;:&quot;This connection string must point to the IoT Hub and is used by ChirpStack Network Server for sending commands to the gateways.&quot;}}}}},&quot;monitoring&quot;:{&quot;bind&quot;:&quot;&quot;,&quot;prometheus_endpoint&quot;:&quot;false&quot;,&quot;prometheus_api_timing_histogram&quot;:&quot;false&quot;,&quot;healthcheck_endpoint&quot;:&quot;false&quot;},&quot;join_server&quot;:{&quot;resolve_join_eui&quot;:&quot;false&quot;,&quot;resolve_domain_suffix&quot;:&quot;.joineuis.lora-alliance.org&quot;,&quot;default&quot;:{&quot;server&quot;:&quot;http://localhost:8003&quot;,&quot;ca_cert&quot;:&quot;&quot;,&quot;tls_cert&quot;:&quot;&quot;,&quot;tls_key&quot;:&quot;&quot;}},&quot;network_controller&quot;:{&quot;server&quot;:&quot;&quot;,&quot;ca_cert&quot;:&quot;&quot;,&quot;tls_cert&quot;:&quot;&quot;,&quot;tls_key&quot;:&quot;&quot;}}
  </code></pre>
  <p>The error I get while running above code is:</p>
  <pre class="lang-py prettyprint-override"><code>Traceback (most recent call last):
    File &quot;&lt;pyshell#38&gt;&quot;, line 1, in &lt;module&gt;
      toml_string = toml.dumps(data)
    File &quot;/usr/local/lib/python3.8/dist-packages/toml/encoder.py&quot;, line 67, in dumps
      raise ValueError(&quot;Circular reference detected&quot;)
  ValueError: Circular reference detected
  </code></pre>
  <p>After digging in, I found that after deleting a key-value pair, the code works fine. The key-value pair is:</p>
  <pre><code>&quot;type&quot;: &quot;mqtt&quot;
  </code></pre>
  <p>The location of this key-value pair is <code>data[&quot;network_server&quot;][&quot;gateway&quot;][&quot;backend&quot;]</code>.</p>
  <p>I am not able to understand this situation.
  I tried to change the key-value pair string but still the same problem. Only removing this key-value pair solves the problem. But I need this pair.</p>
  <p>Any help will be highly appreciated. Thanks in advance.</p>