Open eric-spitler opened 2 years ago
I am also experiencing issues with this when trying to use the sanic-cors extension. Minimal reproducible code below:
from sanic import Sanic
from sanic_cors import CORS
app = Sanic("test_app")
CORS(app)
@app.route('/')
async def test(request):
return "Hello world"
if __name__ == '__main__':
app.run()
Results in:
AttributeError: Setting variables on Sanic instances is not allowed. You should change your Sanic instance to use instance.ctx._startup instead.
Python 3.10
sanic==21.12.0
sanic-plugin-toolkit==1.2.0
sanic-routing==0.7.2
sanic-cors==1.0.1
Hi @eric-spitler and @damianj I want to let you know, I am aware of the issue, I know of the problem and why it exists.
Unfortunately it looks like the methods that Sanic-Plugin-Toolkit uses to hook into Sanic will no longer be supported, and a new mechanism will need to be developed to work on Sanic 21.12 and above. I am currently working on that.
In the meantime, I am going to modify popular plugins (eg, Sanic-CORS) to no longer use Sanic-Plugin-Toolkit, and use the new Sanic features including the new extension mechanism, app context, request context, directly without needing the toolkit.
@eric-spitler and @damianj If you simply need support for Sanic-CORS, please see I've released Sanic-CORS v2.0, which no longer uses Sanic-Plugin-Toolkit, and it now works with Sanic v21.12.0.
Hi @ashleysommer appreciate your work, this issue is also in sanic-restplus as well
Hi @notzippy Yes, I'm aware this affects Sanic restplus too. I am working on a new version of Sanic Plugin Toolkit that will work with Sanic 21.12, but there are some big changes, it's a difficult job.
Besides that, there are some other reasons that Sanic-Restplus will not work on Sanic 21.12 yet. Sanic Restplus has a very low install base, so it's not high on my priority like like eg. Sanic-CORS.
I suggest stay on Sanic v21.9.x if you need to use Sanic-Restplus, that's what I have running in my prod deployments.
Sanic 21.12.0 was release on 12/26/2021 and has breaking changes.
Specifically, it makes setting of attributes on
Sanic
orBlueprint
instances an error where it was previously aDeprecationWarning
. The plugin toolkit tries to wrapSanic._startup
but setting its value, which raises anAttributeError
.Here is a sample section that will raise the
AttributeError
. This line is reached because in 21.12 theSanic.__fake_slots__
becameSanic.__slots__
. https://github.com/ashleysommer/sanic-plugin-toolkit/blob/646820cb23dd2a767afe75c7bda0f901fe9507ba/sanic_plugin_toolkit/realm.py#L999-L1001Furthermore,
Blueprint
objects no longer have__fake_slots__
either, so this section also raisesAttributeError
https://github.com/ashleysommer/sanic-plugin-toolkit/blob/646820cb23dd2a767afe75c7bda0f901fe9507ba/sanic_plugin_toolkit/realm.py#L927-L932