Skip to content

Switch from beaker to flask-session #7893

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

Merged
merged 17 commits into from
May 8, 2024
Merged

Switch from beaker to flask-session #7893

merged 17 commits into from
May 8, 2024

Conversation

smotornyuk
Copy link
Member

Remove beaker and use flask + flask-session instead

@smotornyuk smotornyuk marked this pull request as ready for review November 6, 2023 20:07
smotornyuk and others added 2 commits November 7, 2023 12:28
Co-authored-by: Patricio Del Boca <patriciodelboca@gmail.com>
@pdelboca
Copy link
Member

pdelboca commented Nov 8, 2023

@smotornyuk this one is looking good! and I would love to merge it.

What was the decision on the Tech Team? Are we going to provide support for old config names?

@amercader amercader added this to the CKAN 2.11 milestone Nov 21, 2023
@smotornyuk
Copy link
Member Author

Here's an update for the Redis backend.

flask-sqlalchemy expects the SESSION_REDIS config option to be set to the Redis connection object. If it's empty, Fask will initialize the default connection with localhost:6379, which will fail if Redis runs on a different machine.
I extended the Redis session interface. On the initialization stage, it sets SESSION_REDIS, if empty, to the Redis connection configured in the CKAN config file.

smotornyuk and others added 2 commits December 10, 2023 18:21
@pdelboca
Copy link
Member

Seems okay @smotornyuk !

I'm just adding @wardi and @amercader for an extra pair of eyes.

@pdelboca pdelboca assigned wardi and amercader and unassigned pdelboca Dec 11, 2023
@mhazan01
Copy link

mhazan01 commented Feb 6, 2024

any update on this ? the beaker cache sessions exploding is killing my server.

This involved two internal changes:

1. The import path for `RedisSessionInterface` changed
2. The __init__ parameters for `RedisSessionInterface` changed, now
   requiring `app` to be passed first (see [1])

[1] pallets-eco/flask-session@d30039a#diff-7c52990e5016192ede98e2b9e699d49ef84f7c6735bd10eb9b8e5eba4758c810
option_name = f"ckan.session.custom_type.{session_type}.import_path"

if path := config.get(option_name):
return import_string(path)(app)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Importing arbitrary python code from the INI/environment variables doesn't align with ckan's current pattern of implementing interfaces and enabling plugins. Is there a reason for this different approach here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there isn't an immediate need for this interface I suggest we drop it and discuss the best way to implement pluggable session types. import_string(s) is roughly the same as exec(s) so I'm leery about including it here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, perhaps adding support for custom interfaces is premature. The whole point of Flask-Session is that provides many options already out of the box.
I was also going to suggest that we remove the ckan.session.custom_type.cookie.import_path and ckan.session.custom_type.redis.import_path options. The wrappers @smotornyuk introduced make perfect sense in the context of CKAN, I don't think they need to be customizable.

@amercader
Copy link
Member

@smotornyuk if you can have a quick look at 4325d3a to make sure I haven't missed anything that would be great. I moved the session interface classes to another module to avoid circular import errors.

@smotornyuk
Copy link
Member Author

Everything is good. There is a mention of custom interfaces in changelog: "See :ref:SESSION_TYPE for alternative backends available, including custom ones.", but it may just refer to all 5 session storages supported by flask-session, so it's ok to keep this wording unchanged.

@amercader amercader merged commit 4325d3a into master May 8, 2024
@amercader amercader deleted the remove-beaker branch May 8, 2024 10:05
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

Successfully merging this pull request may close these issues.

5 participants