Skip to content

Badly formatted output when running post-write hooks #1261

Closed

Description

@duc00

Describe the bug
There is a small output bug when running alembic revision ... with a post-write hook. The name of the hook is not correctly displayed:

$ alembic revision -m 'my new revision'        
  Generating myrepo/migrations/versions/202306151538_my_new_revision.py_ ...  done
  Running post write hook {name!r} ... # Display bug HERE
reformatted myrepo/migrations/versions/202306151538_my_new_revision.py

All done! ✨ 🍰 ✨
1 file reformatted.
  done

Happy to fix, if approved!

Expected behavior
This output

$ alembic revision -m 'my new revision'        
  Generating myrepo/migrations/versions/202306151538_my_new_revision.py_ ...  done
  Running post write hook black ... # Display bug HERE
reformatted myrepo/migrations/versions/202306151538_my_new_revision.py

All done! ✨ 🍰 ✨
1 file reformatted.
  done

when black hook is configured.

To Reproduce

$ mkdir testdir
$ cd testdir
$ python3 -m venv venv
$ source venv/bin/activate
$ pip install alembic

Uncomment default post_write_hooks parameters in alembic.ini

[post_write_hooks]
black.type = console_scripts
black.entrypoint = black
black.options = -l 79 REVISION_SCRIPT_FILENAME

Then run revision command

alembic revision -m 'my new revision'

Error

# Command output
  Generating workspace/testdir/migrations/versions/324b3e655f54_my_new_revision.py ...  done
  Running post write hook {name!r} ...
...

Versions.

  • OS: macOS
  • Python: 3.11
  • Alembic: 1.11.1
  • SQLAlchemy: 2.0.16
  • Database: PostgreSQL 15.3
  • DBAPI: N/A

Additional context
Bug seems to be here:

with util.status("Running post write hook {name!r}", newline=True):

Have a nice day!

Activity

  1. CaselIT commented on Jun 15, 2023

    @CaselIT
    Member

    Hi,

    duh. thanks for noticing. strange that no linted said anything about it.
    Care to create a PR for it?

  2. added
    bugSomething isn't working
    and removed
    requires triageNew issue that requires categorization
    on Jun 15, 2023
  3. duc00 commented on Jun 17, 2023

    @duc00
    ContributorAuthor

    Sure!

  4. sqla-tester commented on Jun 17, 2023

    @sqla-tester
    Collaborator

    Mathieu Défosse has proposed a fix for this issue in the main branch:

    Fixed CLI output when running post_write hooks https://gerrit.sqlalchemy.org/c/sqlalchemy/alembic/+/4731

  5. added a commit that references this issue on Sep 27, 2024
    8e786a7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomers

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions