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

Incompatible with Sanic-21.12.0 #25

Open
eric-spitler opened this issue Dec 28, 2021 · 5 comments
Open

Incompatible with Sanic-21.12.0 #25

eric-spitler opened this issue Dec 28, 2021 · 5 comments

Comments

@eric-spitler
Copy link

Sanic 21.12.0 was release on 12/26/2021 and has breaking changes.

Specifically, it makes setting of attributes on Sanic or Blueprint instances an error where it was previously a DeprecationWarning. The plugin toolkit tries to wrap Sanic._startup but setting its value, which raises an AttributeError.

Here is a sample section that will raise the AttributeError. This line is reached because in 21.12 the Sanic.__fake_slots__ became Sanic.__slots__.

if hasattr(app, "_startup"):
# We can wrap startup, to patch _after_ Touchup is done
app._startup = update_wrapper(partial(self._startup, app, app._startup), app._startup)

Furthermore, Blueprint objects no longer have __fake_slots__ either, so this section also raises AttributeError

if SANIC_21_3_0 <= SANIC_VERSION:
_slots = list(Blueprint.__fake_slots__)
_slots.extend(["register"])
Sanic.__fake_slots__ = tuple(_slots)
bp.register = update_wrapper(partial(bp_register, bp, bp.register), bp.register)
setattr(bp.ctx, APP_CONFIG_INSTANCE_KEY, self)

@damianj
Copy link

damianj commented Jan 3, 2022

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

@ashleysommer
Copy link
Owner

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.

@ashleysommer
Copy link
Owner

ashleysommer commented Jan 4, 2022

@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.

@notzippy
Copy link

Hi @ashleysommer appreciate your work, this issue is also in sanic-restplus as well

@ashleysommer
Copy link
Owner

ashleysommer commented Jan 19, 2022

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.

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

4 participants