apache / airflow

Apache Airflow - A platform to programmatically author, schedule, and monitor workflows
https://airflow.apache.org/
Apache License 2.0
36.36k stars 14.1k forks source link

Bad terminal handling of `airflow db shell` command with Postgres DB #26186

Open blag opened 2 years ago

blag commented 2 years ago

Apache Airflow version

main (development)

What happened

This happens in both iTerm 2 and the built-in Terminal.app in macOS when running ~breeze start-airflow~. airflow db shell when using postgres as a backend.

Within psql (run via airflow db shell):

I suspect that there's a lot of interaction happening between iTerm/Terminal.app, ZSH, Python/Breeze, Bash, Docker, tmux, Python/Airflow CLI, and psql, and some keypresses are being filtered or queued along the way. So there are multiple fun rabbit holes to chase down to solve this.

What you think should happen instead

How to reproduce

Operating System

macOS 11.6.8 Big Sur

Versions of Apache Airflow Providers

N/A

Deployment

Other Docker-based deployment

Deployment details

Breeze

Anything else

This happens every time.

Apologies if this isn't the place to report Breeze issues.

Are you willing to submit PR?

Code of Conduct

uranusjr commented 2 years ago

This is from one pane, right? I wonder if this is a Tmux issue (and if that’s the case there’s not much we can do). Can you try entering the shell (with breeze shell or even plain docker run) and run tmux manually, and see if this happens to you as well?

(This could also be related to terminal configuration; terminal emulation is pesky work.)

potiuk commented 2 years ago

This is neither breeze nor tmux problem. This is problem with airflow db shell for postgres and pass-through to pysql which should likely be improved.

You got the exact same behaviour when you use local virtualenv without either of the breeze/tmux (but you can reproduce it easily using breeze as the postgres database setup:

  1. Create airflow virtualenv (an easy way is to activate empty venv and use ./scripts/tools/initialize_virtualenv.py - it will use constraints and you can choose which extras to install)
  2. run breeze --backend postgres --db-reset (this will start and reset the postgres DB as well)
  3. exit breeze
  4. Setup your local venv airflow to connect to the Postgres db of Breeze:
    export AIRFLOW__DATABASE__SQL_ALCHEMY_CONN=postgresql+psycopg2://postgres:airflow@127.0.0.1:25433/airflow

    (you can see Postgres port number user/pasword used printed in the cheathsheet when you start breeze or find it in the docs) 5) Run airflow db shell

Observe the very same behaviour.

potiuk commented 2 years ago

I updated the description to clarify it. Fancy to attempt to fix it @blag ? I think it is the matter of how subprocess is used to run psql

potiuk commented 2 years ago

BTW. I jsut tested it additionally running this in start-airflow pane:

pysql -h postgres -U postgres

(password airflow) Which is equivalent of what breeze db shell does for postgres,

And it behaves as expected - so this is definitely airflow db shell that introduces it

uranusjr commented 2 years ago

Tangentally I’m wondering if it’s a good idea to use dbcli tools for airflow db shell.

potiuk commented 2 years ago

Looks cool. Definitely worth trying how well it works in airflow db. It will likely increase the dependency size, so possibly it should be something that is installed as "extra" ?

github-actions[bot] commented 1 year ago

This issue has been automatically marked as stale because it has been open for 365 days without any activity. There has been several Airflow releases since last activity on this issue. Kindly asking to recheck the report against latest Airflow version and let us know if the issue is reproducible. The issue will be closed in next 30 days if no further activity occurs from the issue author.

blag commented 1 year ago

❌ Still broken - Scrollback editing is messed up - indentation and text wrapping are off/wrong ✅ Fixed...? - Some things require an additional keypress ❌ Still broken - SIGINT isn't registered to cancel editing a query

potiuk commented 1 year ago

Sure. Marked it as good first issue - maybe you would like to fix it @blag ? Otherwise it will have to wait for someone who would like to fix it.

renzepost commented 10 months ago

I can fix the SIGINT issue. I think the problem is in the fact that the TTY is set to raw mode, so in order to send the SIGINT signal to the subprocess, you need to listen for character code 3 in the input data.

The other issues mentioned here are quite puzzling for me though.

potiuk commented 10 months ago

If y ou can move it forward, that would be cool.

potiuk commented 10 months ago

@blag -> do you still the editing issue? Maybe you could take a stab at it and see if it can be fixed as well. Seems that with @renzepost we fixed signal propagation.

blag commented 9 months ago

❌ Still broken - Scrollback editing is messed up - indentation and text wrapping are off/wrong ❌ Still broken - Some things require an additional keypress, including Ctrl+D to exit a DB prompt (with both psql and sqlite) ✅ Fixed - SIGINT isn't registered to cancel editing a query

blag commented 9 months ago

Thank you @renzepost!

renzepost commented 9 months ago

Cool! If I have the time, I'll try to dig a little deeper in the other issues as well.