1

I'm running a flask app, upgraded everything from Python 2.7 to 3 about 5 months ago.

Most things have gone smooth enough, other than this one that's consistently bugging me locally. I'm on a MacBook on OSX 10.12.6, and a brew install of Python 3.6.3 under a virtualenv.

When a request comes in from a page that seemingly has multiple static requests (.css, .js, and image files mainly), I seem to be able to get this error just about anywhere that's using generators anywhere in my code.

Some examples (request is a flask.request object):

A place that checks to see if a path starts with '/static' of '/admin/static' (my code),

any(request.path.startswith(k) for k in self._static_paths)

.

Exception ignored in: <generator object CustomPrincipal._is_static_route.<locals>.<genexpr> at 0x11450f3b8>
Traceback (most recent call last):
  File "/Developer/repos/git/betapilibs/lbbsports/flask_monkeypatches.py", line 22, in <genexpr>
    any(_checker(request.path, k) for k in self._static_paths)
SystemError: error return without exception set

If a url path is restricted, check if the logged in user has the proper permissions / role,

return role in (role.name for role in self.roles) 

.

Exception ignored in: <generator object UserMixin.has_role.<locals>.<genexpr> at 0x1155a7e08>
Traceback (most recent call last):
  File "/Developer/virtualenvs/lbb3/lib/python3.6/site-packages/flask_security/core.py", line 386, in <genexpr>
SystemError: error return without exception set

A custom bit of code to ensure their "sub" account id is valid,

(not any(ident == account_id for ident in account_ids))

.

Exception ignored in: <generator object CustomSession.get_set_accounts.<locals>.<genexpr> at 0x115ff4fc0>
Traceback (most recent call last):
  File "/Developer/customflask/flasklogin.py", line 168, in <genexpr>
SystemError: error return without exception set

Now, nothing seems to break in the system, I just get these error messages, and not consistently, only sometimes. If I set a breakpoint anywhere these errors are being reported to be happening, they don't error any more.

If I do something like, in the first example, break it into request.path.startswith('/static') or request.path.startswith('/admin/static'), I no longer get the error message, and in general, I never have a problem using request all over the place in the rest of the app.

seaders
  • 3,878
  • 3
  • 40
  • 64
  • Smells like a version mismatch somewhere. I would check if any shebang lines reference older Python versions, or if some file (somewhere) is specifically referencing an out-of-date/rev version of something. One Red Flag is the reference to `.../lbbsports/flask_monkeypatches.py`. The monkey patch may think it still 2008 (or something like that). I ran into similar weirdities bringing an old Django site into the 2010's. – Peter Rowell Feb 16 '18 at 17:47
  • I think it's a mismatch too, but with it being a fairly "recent" migration to Python 3, I wouldn't really have expected it. I still don't know how to track it down though, either.. On the monkey patch file, I literally only created that earlier today (similar code had been elsewhere, for forever and been getting the same problem). – seaders Feb 16 '18 at 18:40
  • @PeterRowell, I've just gone through a upgrade to 3.6.4, and created a new virtualenv, but exact same problem. I suppose it still could (must?) be something happening at the underlying C layer, or something like that? – seaders Feb 16 '18 at 20:19
  • @seaders Having the exact same issue here and using 3.6.4 - very frustrating! – Ruthus99 Mar 02 '18 at 10:11
  • See https://stackoverflow.com/a/52054289/3427299 for a solution – Mattwmaster58 Aug 30 '18 at 22:28

1 Answers1

1

A thing that was wrong in my local development setup was that I was serving all the /static and /admin/static through the flask app, instead of serving them through the web-server (in my case, nginx). So for some of the urls I was hitting, there might have been 10 requests come in basically at the same time, with Flask in debug mode, and a debugger connected as well (via PyCharm).

When I went through the trouble to ensure that all '/static' and '/admin/static' get served from there, instead of via flask, and flask was only getting 1 request per url, this problem went away.

I won't mark this as the answer, because there is still an underlying issue, but in case others have the same problem as me, this was a solution for my situation.

seaders
  • 3,878
  • 3
  • 40
  • 64