Warnings on startup from sanic 21 after upgrade from sanic 20

WIth sanic 21 i gt a few warning like this whne starting:

sanic/base.py:35: UserWarning: Setting variables on Sanic instances is deprecated and will be removed in version 21.9. You should change your Sanic instance to use instance.ctx.handle_request instead.
sanic/base.py:35: UserWarning: Setting variables on Sanic instances is deprecated and will be removed in version 21.9. You should change your Sanic instance to use instance.ctx._run_request_middleware instead.
sanic/base.py:35: UserWarning: Setting variables on Sanic instances is deprecated and will be removed in version 21.9. You should change your Sanic instance to use instance.ctx._run_response_middleware instead.

those message repeat once and i couldn’t see any changed behavour in the app.

I use one middleware fore response and request each, but the same messages show up when those methods are commented out.

As i don’t have a stacktrace i can’t offer more insight here.

Do i trigger some old leftover code in sanic with my app init code which was made for sanic 20?

Those are all functions that exist on the Sanic class. How are you initializing your app?

Indentation messed up, but you get the idea…
i don’t think anything special in there… :blush:
I removed some fluff from the code.
the two background jobs just wait for 10s / 10min and check for update of some external data. No black magic there, so i skipped them here.
The blueprints are each in different files.
I use context for some lookups (still not sure if the best way, but redis or alike would be too much…)

The after_server_stop is in main because else it messes up my pytests.

def create_app():
  sanic_app = Sanic(__name__)
  CORS(sanic_app, origins="*", allow_headers="*", supports_credentials=True)

  sanic_app.static(GUI_PREFIX, GUI_PATH + '/index.html')
  sanic_app.static(GUI_PREFIX, GUI_PATH)

  sanic_app.ctx.fax_list = []
  sanic_app.ctx.fax_contents = {}  
  sanic_app.ctx.locks = Locks()
  # add blueprints
  sanic_app.blueprint(static_bp)
  sanic_app.blueprint(main_bp)
  sanic_app.blueprint(fax_bp)
  sanic_app.blueprint(prometheus_bp)
  return sanic_app


if __name__ == "__main__":

   @main_bp.listener('after_server_stop')
   async def clear_faxes(app, loop):
      app.ctx.locks = None


  app = create_app()

  app.add_task(ten_second_job(app))
  app.add_task(ten_minute_job(app))
  app.run(host="0.0.0.0", port=PORT, auto_reload=True, debug=True)

Ahh, I think there is (or will be) an update for sanic-cors for 21.3 support.

But i already have Sanic-Cors 1.0.0…, says pip :confused:

applied like

CORS(sanic_app, origins="*", allow_headers="*", supports_credentials=True)

@ashleysommer? thoughts?

Yes, this is a known issue with Sanic-Plugin-Toolkit.
It is reported here: Deprecation of variables set on Sanic instances · Issue #19 · ashleysommer/sanic-plugin-toolkit · GitHub

These warnings are emitted due to the way SPTK injects itself into the Sanic App. Unfortunately until Sanic v21.6 is released with system-level-signals installed, this is the way it needs to be done.

(Sanic-CORS is built on top of SPTK, thats why it appears like the warnings are generated by Sanic-CORS).

These warnings are harmless, they only appear once, and don’t affect the operation of Sanic or the Plugin.

I am however working on a version of SPTK which will supress the warnings in the meantime.

And now that app.ctx and request.ctx are first-class citizens in Sanic, I have in mind a new lighter and simplifed version of Sanic-CORS which can operate without SPTK installed on the App.

This is fixed now in Sanic Plugin Toolkit v1.0.1

Didn’t found that Bug.
Will ignore this for now.
Sorry for bugging… :wink: