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

mongodb form_subdocument overwrite stopped working after updates to current flask/ flask-admin/ flask-mongoenine #2402

Closed
Bastian-Kuhn opened this issue Dec 14, 2023 · 5 comments

Comments

@Bastian-Kuhn
Copy link
Contributor

Bastian-Kuhn commented Dec 14, 2023

I had to Update the Flask etc. Modules in my Open-Source Project.
One Problem was that I had to replace flask-mongoengine with:
https://github.com/idoshr/flask-mongoengine

So when switching from old to new and reverse, I can reproduce it to work and stop working.
Sadly, I was unable to find out, which project's fault is that nor to fix it.
Even checked the last commit's every and found nothing which could have done it.

Working Versions:
Flask 2.1.2
Flask-Admin: 1.6.0
flask-mongoengine 1.0.0
wtforms 3.0.1

Not working:
Flask 3.0.0
Flask-Admin 1.6.1
flask-mongoengine forkgit@master
wtforms 3.1.1

The Problem is, that the form_widget_args, form_overwrite etc. for the subdocuments are not applied,
I can even add random field names etc. without error, only on the first level I get error messages when the field is wrong.

That's one example from my Code:

form_subdocuments = {
        'conditions': {
            'form_subdocuments' : {
                None: {
                    'form_widget_args': {
                        'hostname_match': {'style': 'background-color: #2EFE9A;' },
                        'hostname': { 'style': 'background-color: #2EFE9A;' },
                        'tag_match': { 'style': 'background-color: #81DAF5;' },
                        'tag': { 'style': 'background-color: #81DAF5;' },
                        'value_match': { 'style': 'background-color: #81DAF5;' },
                        'value': { 'style': 'background-color: #81DAF5;'},
                    },
                    'form_overrides' : {
                        'hostname': StringField,
                        'tag': StringField,
                        'value': StringField,
                    },
                    'form_rules' : [
                        rules.FieldSet(('match_type',), "Condition Match Type"),
                        rules.HTML(divider % "Match on Host"),
                        rules.FieldSet(
                            ('hostname_match', 'hostname', 'hostname_match_negate'), "Host Match"),
                        rules.HTML(divider % "Match on Attribute"),
                        rules.FieldSet(
                            (
                                'tag_match', 'tag', 'tag_match_negate',
                                'value_match', 'value', 'value_match_negate',
                            ), "Attribute Match"),
                    ]
                }
            }
        },
        'outcomes' : {
            'form_subdocuments' : {
                None: {
                    'form_widget_args': {
                        'rule_template' : {"rows": 10},
                    },
                }
            }
        }
    }

And that's the Model for it:

#   .-- Checkmk BI Aggregations

class BiAggregationOutcome(db.EmbeddedDocument):
    """
    BI Aggregation
    """
    description = db.StringField()
    rule_template = db.StringField()



class CheckmkBiAggregation(db.Document):
    """
    BI Aggregation
    """
    name = db.StringField(required=True, unique=True)

    condition_typ = db.StringField(choices=rule_types)
    conditions = db.ListField(field=db.EmbeddedDocumentField(document_type="FullCondition"))
    render_full_conditions = db.StringField() # Helper for Preview

    outcomes = db.ListField(field=db.EmbeddedDocumentField(document_type="BiAggregationOutcome"))
    render_cmk_bi_rule = db.StringField()
    last_match = db.BooleanField(default=False)
    enabled = db.BooleanField()
    meta = {
        'strict': False
    }
#.

Because of the flask-mongoengine version switch, I had to change ListFields to have the field= param, and the EmbeddedDocuments to have the document_type.
Maybe this is related.

Thanks for any help.

@Bastian-Kuhn
Copy link
Contributor Author

For others with the same Problem, found a solution/ workaround. You must replace None with '' to make it work again.

@samuelhwilliams
Copy link
Contributor

I am closing this issue as we're removing support for flask-mongoengine in the next release, because that library is no longer being maintained and is incompatible with recent versions of our core dependencies (eg flask, wtforms, etc).

@samuelhwilliams samuelhwilliams closed this as not planned Won't fix, can't repro, duplicate, stale Aug 7, 2024
@Bastian-Kuhn
Copy link
Contributor Author

@samuelhwilliams I'm I right that I need to migrate to the pymongo module then?

@samuelhwilliams
Copy link
Contributor

If you want to use the upcoming releases of Flask-Admin, that would be my recommendation. I'd be very interested to hear about your experience migrating across - if it's painful, if/what features are missing that we may need to add to pymongo support, etc. pymongo is still seeing regular updates so I think we'd be keen to make sure everything that people need/want to use mongo with Flask-Admin is available there.

@Bastian-Kuhn
Copy link
Contributor Author

Bastian-Kuhn commented Aug 8, 2024

@samuelhwilliams I definitely need to migrate, I heavily use the mongoengine models in this flask-admin based project https://github.com/kuhn-ruess/cmdbsyncer . I also use a lot of Embedded Documents and Styling like this:
grafik (See the first post here)
If the forum_subdocuments worked like before, it would be a big relive. Otherwise this would be the biggest pain. But managable. Besides that, I'm hoping to redefine the Models with the same names, will provide them with access to the existing data. A way for embedded documents should there be also, in the end it has to be written to MongoDB anyway.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

2 participants