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

Refactor logging to use lazy interpolation #2062

Open
xuganyu96 opened this issue Jun 16, 2023 · 2 comments
Open

Refactor logging to use lazy interpolation #2062

xuganyu96 opened this issue Jun 16, 2023 · 2 comments

Comments

@xuganyu96
Copy link
Contributor

While not a bug, it seems like the logging behavior of Flask-AppBuilder is not very consistent. Some logging is done with % formatting, some with .format function call, some with f-strings, and some with lazy interpolation, the last of which is pedantically the "correct" way to log.

Would it make sense to refactor all logging function calls in Flask-AppBuilder to use lazy interpolation? Here is an example of lazy interpolation already being used:

class FilterRelationManyToManyEqual(FilterRelation):
    name = lazy_gettext("Relation as Many")
    arg_name = "rel_m_m"

    def apply_item(self, query, field, value_item):
        """
        Get object by column_name and value_item, then apply filter if object exists
        Query with new filter applied
        """
        try:
            rel_obj = self.datamodel.get_related_obj(self.column_name, value_item)
        except SQLAlchemyError as exc:
            logging.warning(
                "Filter exception for %s with value %s, will not apply",
                field,
                value_item,
            )
            try:
                self.datamodel.session.rollback()
            except SQLAlchemyError:
                # on MSSQL a rollback would fail here
                pass
            raise ApplyFilterException(exception=exc)

        if rel_obj:
            return query.filter(field.contains(rel_obj))
        else:
            log.error(
                "Related object for column: %s, value: %s return Null",
                self.column_name,
                value_item,
            )

        return query
@dpgaspar
Copy link
Owner

it would, totally agree

@xuganyu96
Copy link
Contributor Author

xuganyu96 commented Jun 24, 2023

A quick grep revealed the following places where log is called:

  • ./flask_appbuilder/urltools.py
  • ./flask_appbuilder/security/registerviews.py
  • ./flask_appbuilder/security/sqla/manager.py
  • ./flask_appbuilder/security/mongoengine/manager.py
  • ./flask_appbuilder/security/manager.py
  • ./flask_appbuilder/security/views.py
  • ./flask_appbuilder/security/decorators.py
  • ./flask_appbuilder/tests/test_fab_cli.py
  • ./flask_appbuilder/tests/test_custom_indexview.py
  • ./flask_appbuilder/tests/test_mongoengine.py
  • ./flask_appbuilder/tests/test_mvc.py
  • ./flask_appbuilder/baseviews.py
  • ./flask_appbuilder/utils/base.py
  • ./flask_appbuilder/models/sqla/interface.py
  • ./flask_appbuilder/models/sqla/filters.py
  • ./flask_appbuilder/models/mongoengine/interface.py
  • ./flask_appbuilder/models/group.py
  • ./flask_appbuilder/models/filters.py
  • ./flask_appbuilder/forms.py
  • ./flask_appbuilder/static/appbuilder/js/bootstrap.min.js
  • ./flask_appbuilder/api/init.py
  • ./flask_appbuilder/base.py
  • ./flask_appbuilder/views.py
  • ./bin/hash_db_password.py
  • ./bin/migrate_db_0.7.py
  • ./bin/migrate_db_1.3.py
  • ./examples/basefilter/testdata.py
  • ./examples/quicksqlviews/testdata.py
  • ./examples/related_fields/testdata.py
  • ./examples/user_registration/app/views.py
  • ./examples/composite_keys/testdata.py
  • ./examples/enums/testdata.py
  • ./examples/quickcharts2/app/views.py
  • ./examples/quickcharts2/build/bdist.linux-i686/egg/app/views.py
  • ./examples/quickcharts2/build/lib/app/views.py
  • ./examples/quickmigrate/testdata.py
  • ./examples/quickcharts/app/data.py
  • ./examples/crud_rest_api/testdata.py
  • ./examples/extendsecurity/testdata.py
  • ./examples/quickhowto3/.coverage
  • ./examples/quickhowto3/migrate_db_0.7.py
  • ./examples/extendsecurity2/testdata.py
  • ./examples/quickhowto2/app/templates/new_base.html
  • ./examples/react-rest-api/testdata.py
  • ./examples/quickhowto/testdata.py

Will check off individual file as they are migrated to using lazy interpolation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
2 participants