Python Flask ValueError: Circular reference detected

Question:
Making a forum using Flask but I’m getting an error:

Traceback (most recent call last):
  File "/home/runner/RotoBit-Studios/venv/lib/python3.10/site-packages/flask/app.py", line 2525, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/runner/RotoBit-Studios/venv/lib/python3.10/site-packages/flask/app.py", line 1822, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/runner/RotoBit-Studios/venv/lib/python3.10/site-packages/flask/app.py", line 1820, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/runner/RotoBit-Studios/venv/lib/python3.10/site-packages/flask/app.py", line 1796, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
  File "main.py", line 44, in forumPost
    'url': headers['X-Replit-User-Url'],
  File "/home/runner/RotoBit-Studios/venv/lib/python3.10/site-packages/replit/database/database.py", line 491, in __setitem__
    self.set(key, value)
  File "/home/runner/RotoBit-Studios/venv/lib/python3.10/site-packages/replit/database/database.py", line 500, in set
    self.set_raw(key, _dumps(value))
  File "/home/runner/RotoBit-Studios/venv/lib/python3.10/site-packages/replit/database/database.py", line 56, in dumps
    return json.dumps(val, separators=(",", ":"), cls=DBJSONEncoder)
  File "/nix/store/hd4cc9rh83j291r5539hkf6qd8lgiikb-python3-3.10.8/lib/python3.10/json/__init__.py", line 238, in dumps
    **kw).encode(obj)
  File "/nix/store/hd4cc9rh83j291r5539hkf6qd8lgiikb-python3-3.10.8/lib/python3.10/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/nix/store/hd4cc9rh83j291r5539hkf6qd8lgiikb-python3-3.10.8/lib/python3.10/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
ValueError: Circular reference detected

Idk what the problem is

Repl link:
https://replit.com/@RotoBit-Studios/RotoBit-Studios#main.py

Code Snippet:

@app.route('/forum', methods=['POST'])
def forumPost():
  headers = request.headers
  form = request.form
  title = form['title']
  db[title] = {
    'id': headers['X-Replit-User-Id'],
    'user': headers['X-Replit-User-Name'],
    'pfp': headers['X-Replit-User-Profile-Image'],
    'url': headers['X-Replit-User-Url'],
    'category': form['category'],
    'post': form['post'],
    'date': date.today()
  }
  return redirect(f'/forum?post={title}')

Does this problem still persist?

1 Like

I already answered a topic like this XD

Anyway, your problem is because you are trying to set a date to replit db, which is not json serializable. Do str(yourdate) instead.

2 Likes

For some reason I thought datetime.date.today() returned a string lmao

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.