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

db: upgrade flask-sqlalchemy #97

Merged
merged 1 commit into from
Apr 13, 2023

Conversation

ntarocco
Copy link
Contributor

No description provided.

@ntarocco ntarocco requested a review from utnapischtim April 11, 2023 15:12
@@ -490,7 +490,7 @@ def db(database):
transaction = connection.begin()

options = dict(bind=connection, binds={})
session = database.create_scoped_session(options=options)
session = database._make_scoped_session(options=options)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Comment in an offline chat: we should not use a private method.

Explanation: the method create_scoped_session in flask-sqlalchemy v2 was not private. In v3, it has been replaced by _make_scoped_session, a private method.

Here a relevant issue explaining possible solutions: jeancochrane/pytest-flask-sqlalchemy#63

  1. use the private method
  2. copy/paste the implementation of the private method and use it directly

Copy link
Member

Choose a reason for hiding this comment

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

I would go with using the private function directly. That way, if they remove it we have a clear failure that we will need to fix. If we copy the code, then internal changes in v3, e.g how the sessions are working, might be quite more difficult to be identified and fixed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes that is the solution 2, copy/paste the internal implementation

Copy link
Contributor

Choose a reason for hiding this comment

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

then I would follow the solution 2 since it is exposed as the way of creating the scoped sessions in their documentation, I would expect the public functions exposed in the docs would be more stable than a private method, and I don't see why we would need to go and fix the method each time it is changed internally, rather than relying on something meant to be used, which should keep the backwards compatibility within the minor release range

Copy link
Contributor

Choose a reason for hiding this comment

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

this is the solution from davidism to solve the rollback problem for a fixture. i am not sure if that would be enough for our case, but it seams the more stable approach. is it necessary that we use the session somehow in hour fixture function? if that is necessary then the solution would be not usable, but otherwise we should think about that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@utnapischtim the suggested change is not working, weird errors. I replaced the code with the classic way of creating a scoped session with SQLAlchemy.

Copy link
Contributor

Choose a reason for hiding this comment

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

@ntarocco i tested it too, and i had also weird errors. so no good solution for this use case as you said

@ntarocco ntarocco force-pushed the db-flask-sqlalchemy branch 3 times, most recently from 5b1eb35 to 8dd787c Compare April 12, 2023 15:18
* replaces the previous public method `create_scoped_session` from
  flask-sqlalchemy with the direct way of creating a new session with
  SQLAlchemy. Related GitHub issue:
  jeancochrane/pytest-flask-sqlalchemy#63
@ntarocco ntarocco force-pushed the db-flask-sqlalchemy branch from 8dd787c to d1f2629 Compare April 12, 2023 15:18
@kpsherva kpsherva merged commit 87cf422 into inveniosoftware:master Apr 13, 2023
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.

4 participants