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

login_user_via_session does not work with record transactions #467

Open
jma opened this issue Dec 6, 2023 · 0 comments
Open

login_user_via_session does not work with record transactions #467

jma opened this issue Dec 6, 2023 · 0 comments
Labels

Comments

@jma
Copy link

jma commented Dec 6, 2023

Package version (if known): 3.5.0

Describe the bug

When a record database transaction is done after login_user_via_session the user is not authenticated.

Steps to Reproduce

The following test failed:

def test_authenticated(app):
    from flask import jsonify
    from flask_security import current_user
    from invenio_records.api import Record
    @app.route('/authenticated')
    def authenticated():
        return jsonify(dict(authenticated=current_user.is_authenticated))
    with app.app_context():
        user = create_test_user(email="[email protected]")
        from invenio_accounts import testutils
        with app.test_client() as client:
            testutils.login_user_via_session(client, user)
            Record.create({})
            res = client.get(url_for("authenticated"))
            assert res.status_code == 200
            assert get_json(res)['authenticated']

If we comment the line Record.create({}) or if we move this line before login_user_via_session is works.

Note that using login_user_via_view it works in all cases.

Thanks in advance.

@jma jma added the bug label Dec 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant