Skip to content

Support for Mongoengine in V2.0 #2611

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

Draft
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

Bastian-Kuhn
Copy link
Contributor

Thanks to @karpitsky this brings back the support for Mongoengine, but without the dependency of flask-mongoengine.

Reference: #2541

@Bastian-Kuhn
Copy link
Contributor Author

Only known Problem yet is with the Widgets, but that could be related to an outdated wtforms version.

Also waiting for the tests.

@LeXofLeviafan
Copy link
Contributor

Note: you may want to run the style tests before making the commit (they auto-fix the code style).

I believe it can be done via tox (i.e. tox -e style).

@@ -73,16 +73,16 @@ def create_ajax_loader(model, name, field_name, opts):
prop = getattr(model, field_name, None)

if prop is None:
raise ValueError('Model %s does not have field %s.' % (model, field_name))
raise ValueError(f'Model {model} does not have field {field_name}.' % (model, field_name))
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you forgot to remove the % part 😅

(It may be technically valid code, but there's going to be a runtime error here unless model and/or field_name contain the matching amount of %s placeholders 😆)

@ElLorans
Copy link
Contributor

Note: you may want to run the style tests before making the commit (they auto-fix the code style).

I believe it can be done via tox (i.e. tox -e style).

pip install pre-commit should be enough to do it automatically when committing. Running pre-commit run --all-files allows to do it before committing as well.

@Bastian-Kuhn
Copy link
Contributor Author

Note: you may want to run the style tests before making the commit (they auto-fix the code style).

I believe it can be done via tox (i.e. tox -e style).

Oh thanks, this command changed a lot :)

@Bastian-Kuhn
Copy link
Contributor Author

About the last Tests, Typing, my guess would be to change the requirements/typing.in to add mongoengine?
But what is the proper way for that?

@LeXofLeviafan
Copy link
Contributor

I imagine you need to add mongoengine to the list of packages within that file, then rerun the command written in the .txt file 🙃

(Or possibly mongo-types is what should be added… it could be outdated tho 🤔)

@samuelhwilliams
Copy link
Contributor

samuelhwilliams commented Apr 24, 2025

Yep @LeXofLeviafan is right - if we're adding mongoengine back, we need to add it to our dependency files. This can be a bit of a pain because of how we/pip manages them across multiple files (and probably a good incentive to switch to something more like uv soon...)

Let me know if you need a hand and I can try to help (/work out exactly what to do).

@LeXofLeviafan
Copy link
Contributor

So… any news on this yet?

@Bastian-Kuhn
Copy link
Contributor Author

So… any news on this yet?

If someone could help me with the final check would be nice. Don't want to break something.
And then, that's on me, I need to fix the Bug with the Widgets.

Then everything would be done :)

@ElLorans
Copy link
Contributor

Yep @LeXofLeviafan is right - if we're adding mongoengine back, we need to add it to our dependency files. This can be a bit of a pain because of how we/pip manages them across multiple files (and probably a good incentive to switch to something more like uv soon...)

Let me know if you need a hand and I can try to help (/work out exactly what to do).

Samuel, can you update or tell us how to update the dependencies for type checking? or can I just try to add mongoengine to requirements/typing.txt and run checks locally?

@LeXofLeviafan
Copy link
Contributor

Samuel, can you update or tell us how to update the dependencies for type checking? or can I just try to add mongoengine to requirements/typing.txt and run checks locally?

@samuelhwilliams I believe this was a question for you 😅

@ElLorans based on the comment within that file, the correct answer appears to be "place mongoengine (or mongo-types?) within typing.in then run pip-compile typing.in to update typing.txt"

@samuelhwilliams
Copy link
Contributor

Argh very sorry - thank you for the nudge. Let me give it a go now - it's quite awkward at the moment to get all of the versions of things in different files compatible.

More justification for us/me to switch us over to uv ASAP, probably.

@samuelhwilliams
Copy link
Contributor

samuelhwilliams commented Jun 1, 2025

re: type hints, this issue on mongoengine suggests that the package doesn't really have type hinting support. It mentions an alternative, mongo-types, that also seems outdated and incomplete.

We might want to just disable type hinting on the mongoengine (for now / forever) package by adding it to the ignore_missing_imports block of mypy overrides in pyproject.toml.

In this case no updates will be needed to the requirements files so avoids that sometimes-painful step. But for future reference the principle is vaguely:

  • set up a virtualenv with the correct python version (Based on the header in the *.txt requirements files.
  • Activate the venv and install pip-tools.
  • Run pip-compile on each of the affected requirements files in this order:
    • build.in (only if build.in changed)
    • tests.in (only if tests.in changed)
    • docs.in (if tests.txt or docs.in changed)
    • typing.in (if tests.txt or typing.in changed)
    • dev.in (if docs.txt, tests.in, typing.txt or dev.in changed)

Copy link
Contributor

@samuelhwilliams samuelhwilliams left a comment

Choose a reason for hiding this comment

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

This will also need some amount of test coverage when you get happy with the functionality :)

try:
import mongoengine
except ImportError:
raise Exception("Please install mongoengine in order to use mongoengine backend")
Copy link
Contributor

Choose a reason for hiding this comment

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

Please can we copy the error format from other extensions, which will include adding a reference to flask-admin[mongoengine] - and setting that up as an extra in pyproject.toml.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

5 participants