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

修复调用shell执行mongodb命令时出现WARNING的问题 (hhyo#1237) #1348

Merged
merged 1 commit into from
Jan 18, 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
12 changes: 11 additions & 1 deletion sql/engines/mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,17 @@ def exec_cmd(self, sql, db_name=None, slave_ok=''):
re_msg = []
for line in iter(p.stdout.read, ''):
re_msg.append(line)
msg = '\n'.join(re_msg)
# 因为返回的line中也有可能带有换行符,因此需要先全部转换成字符串
__msg = '\n'.join(re_msg)
_re_msg = []
for _line in __msg.split('\n'):
if not _re_msg and re.match('WARNING.*', _line):
# 第一行可能是WARNING语句,因此跳过
continue
_re_msg.append(_line)

msg = '\n'.join(_re_msg)

except Exception as e:
logger.warning(f"mongo语句执行报错,语句:{sql},{e}错误信息{traceback.format_exc()}")
return msg
Expand Down