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

Support latest flask, sqlalchemy, flask-sqlalchemy and wtforms #2328

Closed
wants to merge 33 commits into from

Conversation

cjmayo
Copy link
Contributor

@cjmayo cjmayo commented Feb 1, 2023

For information on the test failures with the latest versions of these key dependencies and a tracker for some of the fixes from other PRs.

@cjmayo
Copy link
Contributor Author

cjmayo commented Feb 1, 2023

======= 4 failed, 77 passed, 6 xfailed, 10 warnings, 62 errors in 22.46s =======

version3-test.log

@mrjoes
Copy link
Contributor

mrjoes commented Feb 2, 2023

Failed tests because of Flask-SQLAlchemy version lower than 3.0.1 - they fixed __all__.

@cjmayo cjmayo force-pushed the version3 branch 3 times, most recently from 42a30e0 to c3ee6bd Compare February 2, 2023 19:55
@cjmayo
Copy link
Contributor Author

cjmayo commented Feb 2, 2023

Failed tests because of Flask-SQLAlchemy version lower than 3.0.1 - they fixed __all__.

I had missed that MarkupSafe was still restricted and that was limiting Flask-SQLAlchemy to 2.5.1.

Removed that restriction, and the monoengine ones - only the necessary azure-storage-blob restriction is left here now.

After merging in master with the BaseView fix:

========== 13 failed, 130 passed, 6 xfailed, 17016 warnings in 39.83s ==========

I undid the xfail from sqla/test_basic test_different_bind_joins and added a selection of patches from other PRs and:

========== 5 failed, 139 passed, 5 xfailed, 24725 warnings in 50.02s ===========

And one of those failures should be easy:

 >           db.engine.execute('CREATE EXTENSION IF NOT EXISTS citext')
 E           AttributeError: 'Engine' object has no attribute 'execute'

just needs changing to the new sqlalchemy 2 style.

@cjmayo cjmayo force-pushed the version3 branch 5 times, most recently from 9ee431b to 62d0f7b Compare February 3, 2023 19:57
@cjmayo
Copy link
Contributor Author

cjmayo commented Feb 3, 2023

I think I'm getting there. The one I definitely don't think I can fix is flask_admin/tests/sqla/test_inlineform.py::test_inline_form_base_class. Not the common setup() failure in the latest logs, that's masked:

 >           assert b'success!' in rv.data, rv.data
 E           AssertionError: b'
 E             <!DOCTYPE html>

it does appear to be WTForms 3 related but I don't have the Flask skills to debug.

@cjmayo
Copy link
Contributor Author

cjmayo commented Feb 4, 2023

========== 1 failed, 143 passed, 5 xfailed, 24992 warnings in 39.42s ===========

That's as far as I think I can get. Last failure, as above, WTForms 3 related:

flask_admin/tests/sqla/test_inlineform.py:307: AssertionError

    def test_inline_form_base_class():
...
             # Create
             data = {
                 'name': 'emptyEmail',
                 'emails- '',
             }
             rv = client.post('/admin/user/new/', data=data)
             assert rv.status_code == 
             assert User.query.count() == 
 >           assert b'success!' in rv.data, rv.data
 E           AssertionError: b'
 E             <!DOCTYPE html>

@cjmayo
Copy link
Contributor Author

cjmayo commented Feb 8, 2023

Resolved the test_inlineform failure, form._getranslations was deprecated in WTForms 2.0 and removed in 3.

Now we have a bunch of new failures...

@cjmayo cjmayo force-pushed the version3 branch 2 times, most recently from 0948af6 to ddf6024 Compare February 9, 2023 19:30
@cjmayo
Copy link
Contributor Author

cjmayo commented Feb 9, 2023

Just as it was nearly there a new release of SQLAlchemy, 2.0.2, came out which breaks Flask-Admin.

Commit added to fix that. More in the commit message, but the solution here does mean dropping SQLAlchemy 1.3 and therefore also SQLAlchemy-Utils 0.36. I think that is the cleanest way of doing it, but maybe there are other opinions.

@cjmayo
Copy link
Contributor Author

cjmayo commented Oct 25, 2023

Probably worth making it clear then that this PR only covers tests and flask_admin itself, not the examples.

Because of Flask-BabelEx or Flask-MongoEngine the examples will be at most Flask < 3. examples/sqla/requirements.txt as per Step 3 of the linked instructions could be updated (plus the ones in all the subdirectories checked).

@cjmayo cjmayo changed the title Support latest flask, sqlalchemy, flask-sqlalchemy and wtforms Support latest flask, sqlalchemy, flask-sqlalchemy and wtforms < 3.1.0 Oct 25, 2023
bmwiedemann pushed a commit to bmwiedemann/openSUSE that referenced this pull request Oct 26, 2023
https://build.opensuse.org/request/show/1120478
by user mcalabkova + anag+factory
- Add few patches to fix tests (from gh#pallets-eco/flask-admin#2328):
  * model-from-model.patch
  * reverse-relation-for-model.patch
  * bytes-not-str.patch
dgilman and others added 18 commits November 1, 2023 19:21
"AssertionError: The setup method 'register_blueprint' can no longer be called on the application. It has already handled its first request, any changes will not be applied consistently. Make sure all imports, decorators, functions, etc. needed to set up the application are done before running it."
FAILED tests/test_model.py::test_export_csv - AssertionError: assert 'Col1,Col2\r\..._3,col2_3\r\n' == 'Col1,Col2\r\...,–utf8_2–\r\n'
sqlalchemy.exc.UnboundExecutionError: Bind key 'other' is not in 'SQLALCHEMY_BINDS' config.
 >       assert model.test == ''
 E       AssertionError: assert None == ''
 E        +  where None = <Model test

WTForms 3 changed StringField data default value.
 >           db.engine.execute('CREATE EXTENSION IF NOT EXISTS citext')
 E           AttributeError: 'Engine' object has no attribute 'execute'
SQLAlchemy 2.0.2 removed the invocation of registry.configure() from
Mapper.iterate_properties causing this problem.

sqlalchemy.orm.registry.configure() was added in 1.4.0b2.

Observed as test failures in:

flask_admin/tests/sqla/test_basic.py
flask_admin/tests/sqla/test_form_rules.py
flask_admin/tests/sqla/test_inlineform.py
LegacyAPIWarning: The Query.get() method is considered legacy as of the
1.x series of SQLAlchemy and becomes a legacy construct in 2.0.
The method is now available as Session.get() (deprecated since: 2.0)
E           sqlalchemy_utils.exceptions.ImproperlyConfigured: 'babel' package is required in order to use CurrencyType.

.tox/py/lib/python3.9/site-packages/sqlalchemy_utils/types/currency.py:55: ImproperlyConfigured
            assert rv.location.startswith(expected)
>           assert 'url=http%3A%2F%2Flocalhost%2Fadmin%2Fmodel2view%2F' in rv.location
E           AssertionError: assert 'url=http%3A%2F%2Flocalhost%2Fadmin%2Fmodel2view%2F' in '/admin/model1/edit/?id=1&url=http://localhost/admin/model2view/'
E            +  where '/admin/model1/edit/?id=1&url=http://localhost/admin/model2view/' = <WrapperTestResponse streamed [302 FOUND]>.location

flask_admin/tests/sqla/test_basic.py:2466: AssertionError
@cjmayo cjmayo changed the title Support latest flask, sqlalchemy, flask-sqlalchemy and wtforms < 3.1.0 Support latest flask, sqlalchemy, flask-sqlalchemy and wtforms Nov 1, 2023
@samuelhwilliams
Copy link
Contributor

I am going to close this as outdated as we've just updated the testing framework for flask-admin after it was incorporated into the pallets-eco project.

I do think we need to address the testing situation to have better variant testing on some key dependencies, however that may be best to look at from a fresh slate now. Please don't take this as discouragement from helping tighten this up, but as this PR is fairly stale now I think a reboot would be best.

@cjmayo cjmayo deleted the version3 branch July 21, 2024 18:24
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 5, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

5 participants