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

fix(admin): capture migration output on stdout #3508

Merged
merged 1 commit into from
Dec 13, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion snuba/admin/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import io
import sys
from contextlib import redirect_stdout
from dataclasses import asdict
from typing import Any, List, Mapping, Optional, Sequence, Tuple, cast
Expand Down Expand Up @@ -191,7 +192,15 @@ def do_action() -> None:
try:
# temporarily redirect stdout to a buffer so we can return it
with io.StringIO() as output:
with redirect_stdout(output):
# write output to both the buffer and stdout
class OutputRedirector(io.StringIO):
stdout = sys.stdout

def write(self, s: str) -> int:
self.stdout.write(s)
return output.write(s)

with redirect_stdout(OutputRedirector()):
do_action()
return make_response(jsonify({"stdout": output.getvalue()}), 200)

Expand Down