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

RuntimeError: dictionary keys changed during iteration #117

Open
SharjeelBaig0508 opened this issue Nov 22, 2021 · 0 comments
Open

RuntimeError: dictionary keys changed during iteration #117

SharjeelBaig0508 opened this issue Nov 22, 2021 · 0 comments

Comments

@SharjeelBaig0508
Copy link

SharjeelBaig0508 commented Nov 22, 2021

image

I'm using MongoDB with flask profiler and when I used the filtering feature of flask profiler and checked the logs of my app it returns:

2021-11-20T08:34:14.991801+00:00 app[web.1]: [2021-11-20 08:34:14 +0000] [10] [ERROR] Error handling request /flask-profiler/api/measurements/?method=POST&name=%2Fapi%2Fv1%2Ftest%2Fread&elapsed=0&sort=startedAt%2Cdesc&skip=0&limit=100&startedAt=1636878787&endedAt=1637397187
2021-11-20T08:34:14.991808+00:00 app[web.1]: Traceback (most recent call last):
2021-11-20T08:34:14.991809+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/workers/sync.py", line 136, in handle
2021-11-20T08:34:14.991809+00:00 app[web.1]: self.handle_request(listener, req, client, addr)
2021-11-20T08:34:14.991810+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/workers/sync.py", line 179, in handle_request
2021-11-20T08:34:14.991810+00:00 app[web.1]: respiter = self.wsgi(environ, resp.start_response)
2021-11-20T08:34:14.991810+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/flask/app.py", line 2088, in call
2021-11-20T08:34:14.991811+00:00 app[web.1]: return self.wsgi_app(environ, start_response)
2021-11-20T08:34:14.991811+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/flask/app.py", line 2073, in wsgi_app
2021-11-20T08:34:14.991811+00:00 app[web.1]: response = self.handle_exception(e)
2021-11-20T08:34:14.991811+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/flask/app.py", line 2070, in wsgi_app
2021-11-20T08:34:14.991812+00:00 app[web.1]: response = self.full_dispatch_request()
2021-11-20T08:34:14.991812+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/flask/app.py", line 1515, in full_dispatch_request
2021-11-20T08:34:14.991812+00:00 app[web.1]: rv = self.handle_user_exception(e)
2021-11-20T08:34:14.991813+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/flask/app.py", line 1513, in full_dispatch_request
2021-11-20T08:34:14.991813+00:00 app[web.1]: rv = self.dispatch_request()
2021-11-20T08:34:14.991813+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/flask/app.py", line 1499, in dispatch_request
2021-11-20T08:34:14.991813+00:00 app[web.1]: return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
2021-11-20T08:34:14.991813+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/flask_httpauth.py", line 172, in decorated
2021-11-20T08:34:14.991814+00:00 app[web.1]: return self.ensure_sync(f)(*args, **kwargs)
2021-11-20T08:34:14.991814+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/flask_profiler/flask_profiler.py", line 194, in filterMeasurements
2021-11-20T08:34:14.991815+00:00 app[web.1]: return jsonify({"measurements": list(measurements)})
2021-11-20T08:34:14.991815+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/flask_profiler/storage/mongo.py", line 81, in
2021-11-20T08:34:14.991815+00:00 app[web.1]: return (self.clearify(record) for record in cursor)
2021-11-20T08:34:14.991815+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/flask_profiler/storage/mongo.py", line 251, in clearify
2021-11-20T08:34:14.991816+00:00 app[web.1]: for k, v in obj.items():
2021-11-20T08:34:14.991816+00:00 app[web.1]: RuntimeError: dictionary keys changed during iteration

I investigated on flask-profiler/storage/mongo.py and noticed this error and found a solution for this:

Suggested Solution:

in flask-profiler/flask_profiler/storage/mongo.py at line 251:
Just replace for k, v in obj.items(): with for k, v in dict(obj.items()):

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

1 participant