rhysyngsun
(Nathan Levesque)
May 24, 2023, 3:48pm
1
I opened an issue on edx-platform regarding this, it’s likely one of our team (MIT Open Learning) will work on this, but I wanted to post here for additional visibility.
opened 03:45PM - 24 May 23 UTC
Calling `str()` on an instance of this model causes a network request via a call… to `BulkEmailFlag.current` rather than operating on `self`. It's atypical for `__str__` to be an impure method, although I haven't seen any developer guidance to avoid it. This behavior can actually cause an infinite recursion to occur, which we recently encountered with a recent version of `sentry_sdk`, which introduced [a change](https://github.com/getsentry/sentry-python/commit/efa55d32c75c90f6bf4afab5d7c8032797821430#diff-cf95cda97525d2430abeda290d49707dd3ac7aed8752350b11914e71f7c731f5R42) that calls `str()` (aliased as `text_type` in that commit) on the return value of network calls. In the case we ran into the call to Redis to retrieve the cached instance of `BulkEmailFlag.current` was being instrumented and caused the `RecursionError`.
Here's a stacktrace that illustrates what we were seeing (1500 lines, so linking to a gist of it): https://gist.github.com/rhysyngsun/76439b141907f42e75eaea42f9542c1c
I think it's prudent to remove the call to `BulkEmailFlag.current` in `BulkEmailFlag.__str__` and have it operate on `self` instead.