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

reverting json setting to use json_encoder despite warnings #26546

Conversation

gfeldman
Copy link

@gfeldman gfeldman commented Sep 21, 2022

closes: 26527

The flask_app.json_provider_class does not take a JsonEncoder as an argument. Reverting the setting to flask_app.json_encoder despite deprecation warnings until a provider can be written.

@boring-cyborg
Copy link

boring-cyborg bot commented Sep 21, 2022

Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contribution Guide (https://github.com/apache/airflow/blob/main/CONTRIBUTING.rst)
Here are some useful points:

  • Pay attention to the quality of your code (flake8, mypy and type annotations). Our pre-commits will help you with that.
  • In case of a new feature add useful documentation (in docstrings or in docs/ directory). Adding a new operator? Check this short guide Consider adding an example DAG that shows how users should use it.
  • Consider using Breeze environment for testing locally, it's a heavy docker but it ships with a working Airflow and a lot of integrations.
  • Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
  • Please follow ASF Code of Conduct for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
  • Be sure to read the Airflow Coding style.
    Apache Airflow is a community-driven project and together we are making it better 🚀.
    In case of doubts contact the developers at:
    Mailing List: [email protected]
    Slack: https://s.apache.org/airflow-slack

@boring-cyborg boring-cyborg bot added the area:webserver Webserver related Issues label Sep 21, 2022
@gfeldman
Copy link
Author

with flask_app.json_encoder = AirflowJsonEncoder setting

>>> from airflow.www import app
>>> from kubernetes.client import models as k8s
>>> p = k8s.V1Pod(spec=k8s.V1PodSpec(containers=[k8s.V1Container(name="base")]))
>>> c = app.create_app()
>>> c.json.dumps(p)
'{"spec": {"containers": [{"name": "base"}]}}'

with flask_app.json_provider_class = AirflowJsonEncoder

>>> from airflow.www import app
>>> from kubernetes.client import models as k8s
>>> p = k8s.V1Pod(spec=k8s.V1PodSpec(containers=[k8s.V1Container(name="base")]))
>>> c = app.create_app()
>>> c.json.dumps(p)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/guy.feldman/opt/anaconda3/lib/python3.9/site-packages/flask/json/provider.py", line 230, in dumps
    return json.dumps(obj, **kwargs)
  File "/Users/guy.feldman/opt/anaconda3/lib/python3.9/json/__init__.py", line 234, in dumps
    return cls(
  File "/Users/guy.feldman/opt/anaconda3/lib/python3.9/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/Users/guy.feldman/opt/anaconda3/lib/python3.9/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "/Users/guy.feldman/opt/anaconda3/lib/python3.9/site-packages/flask/json/provider.py", line 122, in _default
    raise TypeError(f"Object of type {type(o).__name__} is not JSON serializable")
TypeError: Object of type V1Pod is not JSON serializable

@ashb
Copy link
Member

ashb commented Sep 21, 2022

This fix is incorrect, json_encoder is now deprecated in Flask 2.2 and will be removed in flask 2.3
https://flask.palletsprojects.com/en/2.2.x/api/?highlight=json_provider_class#flask.Flask.json_encoder

So we'll need to find a different fix.

@ashb
Copy link
Member

ashb commented Sep 21, 2022

Closing in favour of #26554. Thank you for the debugging steps, they made it very easy for me to fix.

@ashb ashb closed this Sep 21, 2022
@gfeldman gfeldman deleted the gfeldman.26527.revert_json_encoder_app_setting branch September 21, 2022 12:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:webserver Webserver related Issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

UI error when clicking on graph view when a task has pod overrides
2 participants