Circular reference detected Error when login

274 views
Skip to first unread message

Christian Varas

unread,
Feb 24, 2022, 5:01:58 PM2/24/22
to py4web
Hi, i'm having issues with the following error:

File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 436, in _iterencode

    raise ValueError("Circular reference detected")

ValueError: Circular reference detected


I'm having this error when I try to log in. 
I can't figure out where can be the error is.

Any help is appreciated!

Cheers.

Christian Varas

unread,
Feb 25, 2022, 4:11:52 PM2/25/22
to py4web
thanks, I've checked but i'm not seeing issues in my redirect.

The error "ValueError: Circular reference detected" occurs when I try to log in.
Also If i try to register or use any other auth endpoint i receive the response in json format, if i try to log in i receive the error message in json format. The template is not being recognized.

image.png

All my actions are written like this:
@action.uses(session, db, flash, auth.user)
or
@action.uses('template.html', session, db, flash, auth.user)


Auth declaration is like this:

# Instantiate the object and actions that handle auth
# #######################################################
auth = Auth(session, db, define_tables=False)
auth.use_username = False
auth.param.registration_requires_confirmation = settings.VERIFY_EMAIL
auth.param.registration_requires_approval = settings.REQUIRES_APPROVAL
auth.allowed_actions = settings.ALLOWED_ACTIONS
auth.login_expiration_time = 3600
auth.password_complexity = {"entropy": 50}
auth.block_previous_password_num = 3
auth.define_tables()



this is the complete traceback:

Ombott v0.0.13 server starting up (using RocketServer(reloader=False))...

Listening on http://127.0.0.1:8000/

watching (lazy-mode) python file changes in: /Users/chris/Library/Mobile Documents/com~apple~CloudDocs/develop/py4web/apps

Hit Ctrl-C to quit.


[2022-02-25T17:57:13.463933]: Traceback (most recent call last):

  File "/Users/chris/Library/Mobile Documents/com~apple~CloudDocs/develop/py4web/py4web/core.py", line 955, in wrapper

    ret = dumps(ret)

  File "/Users/chris/Library/Mobile Documents/com~apple~CloudDocs/develop/py4web/py4web/core.py", line 297, in dumps

    return json.dumps(obj, default=objectify, sort_keys=sort_keys, indent=indent)

  File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/__init__.py", line 234, in dumps

    return cls(

  File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 201, in encode

    chunks = list(chunks)

  File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 431, in _iterencode

    yield from _iterencode_dict(o, _current_indent_level)

  File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 405, in _iterencode_dict

    yield from chunks

  File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 439, in _iterencode

    yield from _iterencode(o, _current_indent_level)

  File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 431, in _iterencode

    yield from _iterencode_dict(o, _current_indent_level)

  File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 405, in _iterencode_dict

    yield from chunks

  File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 325, in _iterencode_list

    yield from chunks

  File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 405, in _iterencode_dict

    yield from chunks

  File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 325, in _iterencode_list

    yield from chunks

  File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 405, in _iterencode_dict

    yield from chunks

  File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 325, in _iterencode_list

    yield from chunks

  File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 439, in _iterencode

    yield from _iterencode(o, _current_indent_level)

  File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 431, in _iterencode

    yield from _iterencode_dict(o, _current_indent_level)

  File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 405, in _iterencode_dict

    yield from chunks

  File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 439, in _iterencode

    yield from _iterencode(o, _current_indent_level)

  File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 431, in _iterencode

    yield from _iterencode_dict(o, _current_indent_level)

  File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 405, in _iterencode_dict

    yield from chunks

  File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 436, in _iterencode

    raise ValueError("Circular reference detected")

ValueError: Circular reference detected


ERROR:root:Traceback (most recent call last):

  File "/Users/chris/Library/Mobile Documents/com~apple~CloudDocs/develop/py4web/py4web/core.py", line 955, in wrapper

    ret = dumps(ret)

  File "/Users/chris/Library/Mobile Documents/com~apple~CloudDocs/develop/py4web/py4web/core.py", line 297, in dumps

    return json.dumps(obj, default=objectify, sort_keys=sort_keys, indent=indent)

  File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/__init__.py", line 234, in dumps

    return cls(

  File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 201, in encode

    chunks = list(chunks)

  File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 431, in _iterencode

    yield from _iterencode_dict(o, _current_indent_level)

  File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 405, in _iterencode_dict

    yield from chunks

  File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 439, in _iterencode

    yield from _iterencode(o, _current_indent_level)

  File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 431, in _iterencode

    yield from _iterencode_dict(o, _current_indent_level)

  File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 405, in _iterencode_dict

    yield from chunks

  File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 325, in _iterencode_list

    yield from chunks

  File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 405, in _iterencode_dict

    yield from chunks

  File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 325, in _iterencode_list

    yield from chunks

  File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 405, in _iterencode_dict

    yield from chunks

  File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 325, in _iterencode_list

    yield from chunks

  File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 439, in _iterencode

    yield from _iterencode(o, _current_indent_level)

  File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 431, in _iterencode

    yield from _iterencode_dict(o, _current_indent_level)

  File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 405, in _iterencode_dict

    yield from chunks

  File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 439, in _iterencode

    yield from _iterencode(o, _current_indent_level)

  File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 431, in _iterencode

    yield from _iterencode_dict(o, _current_indent_level)

  File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 405, in _iterencode_dict

    yield from chunks

  File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 436, in _iterencode

    raise ValueError("Circular reference detected")

ValueError: Circular reference detected



Cheers.

El jue, 24 feb 2022 a las 20:20, John Bannister (<eudor...@gmail.com>) escribió:
Normally when you are redirecting to calling action either directly or via another action. Check redirects


--
You received this message because you are subscribed to the Google Groups "py4web" group.
To unsubscribe from this group and stop receiving emails from it, send an email to py4web+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/py4web/CA%2Bs%2BuJtJGD6ATpHqsjYd6ix6RbxOMsBJUwEdiF6_pgjqskBXcg%40mail.gmail.com.

Jim Steil

unread,
Feb 26, 2022, 8:38:03 AM2/26/22
to py4web
Are you able to reproduce this is any other apps?  Can you create a minimal app that shows the same behavior?

-Jim

Christian Varas

unread,
Feb 26, 2022, 11:07:22 AM2/26/22
to py4web

I'm using Py4web: 1.20220222.1 on Python 3.9.10 (i've cloned a few hours ago)
All functions are composed with this: actions.uses('template.html', session, db. flash, auth)

I think i found the issue... when an error occurs at view level, it doesn't show a traceback with the detail. Instead, respond to the browser with an error in json format (not like the usual html 500 error page) and in the console it doesn't show an error message.

I've modified the index.html of the example app in templates/index.html and after the layout extension, I've added a variable that doesn't exist and should case an error.
ex:
[[extend 'layout.html']]
[[=cscdcd]]  <!--should cause error -->

response in browser:
image.png
no error on console:
Ombott v0.0.13 server starting up (using RocketServer(reloader=False))...
Hit Ctrl-C to quit.

watching (lazy-mode) python file changes in: /Users/chris/Library/Mobile Documents/com~apple~CloudDocs/develop/py4web/apps




I have another app that works correctly and if i add a non existing variable in a view it throws the error about "circular reference detected" and in the browser the response is in json and not wit

in index.html; 
[[extend 'layout.html']]
  [[=sss]]  <!--should cause error -->

error in browser

image.png
error in console:

ERROR:root:Traceback (most recent call last):

  File "/Users/chris/Library/Mobile Documents/com~apple~CloudDocs/develop/py4web/py4web/core.py", line 955, in wrapper

    ret = dumps(ret)

  File "/Users/chris/Library/Mobile Documents/com~apple~CloudDocs/develop/py4web/py4web/core.py", line 297, in dumps

    return json.dumps(obj, default=objectify, sort_keys=sort_keys, indent=indent)

  File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/__init__.py", line 234, in dumps

    return cls(

  File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 201, in encode

    chunks = list(chunks)

  File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 431, in _iterencode

    yield from _iterencode_dict(o, _current_indent_level)

  File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 405, in _iterencode_dict

    yield from chunks

  File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 439, in _iterencode

    yield from _iterencode(o, _current_indent_level)

  File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 431, in _iterencode

    yield from _iterencode_dict(o, _current_indent_level)

  File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 405, in _iterencode_dict

    yield from chunks

  File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 439, in _iterencode

    yield from _iterencode(o, _current_indent_level)

  File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 431, in _iterencode

    yield from _iterencode_dict(o, _current_indent_level)

  File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 405, in _iterencode_dict

    yield from chunks

  File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 325, in _iterencode_list

    yield from chunks

  File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 405, in _iterencode_dict

    yield from chunks

  File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 325, in _iterencode_list

    yield from chunks

  File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 439, in _iterencode

    yield from _iterencode(o, _current_indent_level)

  File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 431, in _iterencode

    yield from _iterencode_dict(o, _current_indent_level)

  File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 405, in _iterencode_dict

    yield from chunks

  File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 439, in _iterencode

    yield from _iterencode(o, _current_indent_level)

  File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 431, in _iterencode

    yield from _iterencode_dict(o, _current_indent_level)

  File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 405, in _iterencode_dict

    yield from chunks

  File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 439, in _iterencode

    yield from _iterencode(o, _current_indent_level)

  File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 431, in _iterencode

    yield from _iterencode_dict(o, _current_indent_level)

  File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 405, in _iterencode_dict

    yield from chunks

  File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 325, in _iterencode_list

    yield from chunks

  File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 405, in _iterencode_dict

    yield from chunks

  File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 325, in _iterencode_list

    yield from chunks

  File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 405, in _iterencode_dict

    yield from chunks

  File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 284, in _iterencode_list

    raise ValueError("Circular reference detected")

ValueError: Circular reference detected


I don't know why one app throws the error about "Circular reference detected" when the error happens in the view and the other app doesn't show this error. But adding a non existing variable to a view will trigger this behavior.

I finally spotted where in my template was the issue and now i'm able to log in and keep working on the app! 

Should I open an issue in github?

Thanks!

Cheers.
Chris.

Luca de Alfaro

unread,
Feb 26, 2022, 11:19:48 AM2/26/22
to Christian Varas, py4web
Ret in core.py seems to have a circular reference in it. Can you investigate? Or provide a small app where it happens?

Luca

--
Luca

Christian Varas

unread,
Feb 28, 2022, 9:39:21 AM2/28/22
to py4web
I believe there is no need to give an example app, due to this error/behavior is appearing just when you provoke an error in the view.

You can try with the example app. Go to index.html and add any non-existent variable like: [[=asdasd]]. This should trigger the error ending with a json response (losing html format) and showing the error  circular dereference detected.

More than the error of circular dependency, there is no useful traceback when the error is triggered in the template. Is Hard to fix the app because I don't know where it fails, so I have to go and comment lines one by one to try to catch the one who provokes the error.

I could create a POC video if needed.

Cheers.
Chris.





Massimo DiPierro

unread,
Feb 28, 2022, 10:18:35 AM2/28/22
to Christian Varas, py4web
Thank you. Will look into this later today 

Massimo

unread,
Mar 3, 2022, 11:55:53 PM3/3/22
to py4web
I am looking into this. There is indeed a problem (my template with the error is ignored) but I do not observe a circular reference or a traceback (I should).

Massimo DiPierro

unread,
Mar 4, 2022, 12:03:53 AM3/4/22
to py4web
I found a problem in handling exceptions occurring in on_success/on_failure. It works well for me now. Yet I was never able to reproduce the circular reference. Please check if this fixes it for you.

Christian Varas

unread,
Mar 4, 2022, 7:45:30 AM3/4/22
to Massimo DiPierro, py4web
Thank you Massimo, now i can see the errors in the template, and the error of "circular reference" is gone. :D

Thanks again!.
Cheers.

Reply all
Reply to author
Forward
0 new messages