dbcli / mycli

A Terminal Client for MySQL with AutoCompletion and Syntax Highlighting.
http://mycli.net
Other
11.49k stars 663 forks source link

Output not displayed in table format #1025

Closed Tae-juss closed 2 years ago

Tae-juss commented 2 years ago

When querying the DB for basic output with \G, mycli is returning "'str' object has no attribute 'parent'" error. Output is only displayed if requested in GRID format.

Please find the sample below:

================================ DB> select id from bag LIMIT 1 'str' object has no attribute 'parent'

DB> select id from bag LIMIT 1\G [ 1. row ] id | 2 1 row in set Time: 0.001s

DB> select id from bag LIMIT 1; 'str' object has no attribute 'parent'

================================ image

amjith commented 2 years ago

@Tae-juss If you check your log file there should be an exception traceback. You can find the log file under ~/.mycli.log

Can you paste the relevant lines here? (Make sure to remove any sensitive data from the log lines).

amjith commented 2 years ago

I can't trigger the error locally. Can you tell me what is the data type of the id column?

rrain7 commented 2 years ago

I can't trigger the error locally. Can you tell me what is the data type of the id column?

hello, I have the same issue. My Env:

when I input show tables get 'str' object has no attribute 'parent' the log:

2022-01-09 20:16:58,881 (54249/MainThread) mycli.main ERROR - sql: 'show tables', error: AttributeError("'str' object has no attribute 'parent'") 2022-01-09 20:16:58,884 (54249/MainThread) mycli.main ERROR - traceback: 'Traceback (most recent call last):\n File "/opt/homebrew/lib/python3.9/site-packages/pygments/formatters/terminal256.py", line 261, in format_unencoded\n on, off = self.style_string[str(ttype)]\nKeyError: \'Token.Output.TableSeparator\'\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n File "/opt/homebrew/lib/python3.9/site-packages/mycli/main.py", line 711, in one_iteration\n formatted = self.format_output(\n File "/opt/homebrew/lib/python3.9/site-packages/mycli/main.py", line 1029, in format_output\n formatted = self.formatter.format_output(\n File "/opt/homebrew/lib/python3.9/site-packages/cli_helpers/tabular_output/output_formatter.py", line 168, in format_output\n data, headers = f(data, headers, column_types=column_types, *fkwargs)\n File "/opt/homebrew/lib/python3.9/site-packages/cli_helpers/tabular_output/tabulate_adapter.py", line 170, in style_output\n newfmt = tabulate.TableFormat((addColorInElt(val) for val in srcfmt))\n File "/opt/homebrew/lib/python3.9/site-packages/cli_helpers/tabular_output/tabulate_adapter.py", line 170, in \n newfmt = tabulate.TableFormat((addColorInElt(val) for val in srcfmt))\n File "/opt/homebrew/lib/python3.9/site-packages/cli_helpers/tabular_output/tabulate_adapter.py", line 160, in addColorInElt\n return tabulate.Line(\n File "/opt/homebrew/lib/python3.9/site-packages/cli_helpers/tabular_output/tabulate_adapter.py", line 161, in \n (style_field(table_separator_token, val) for val in elt)\n File "/opt/homebrew/lib/python3.9/site-packages/cli_helpers/tabular_output/tabulate_adapter.py", line 153, in style_field\n formatter.format(((token, field),), s)\n File "/opt/homebrew/lib/python3.9/site-packages/pygments/formatters/terminal256.py", line 250, in format\n return Formatter.format(self, tokensource, outfile)\n File "/opt/homebrew/lib/python3.9/site-packages/pygments/formatter.py", line 94, in format\n return self.format_unencoded(tokensource, outfile)\n File "/opt/homebrew/lib/python3.9/site-packages/pygments/formatters/terminal256.py", line 282, in format_unencoded\n ttype = ttype.parent\nAttributeError: \'str\' object has no attribute \'parent\'\n'

ttys3 commented 2 years ago

related upstream commit: https://github.com/pygments/pygments/commit/8fdd6b9879a6c34b908fa03a6ff15f764192a54e

upstream related issue: https://github.com/pygments/pygments/issues/2027

ttys3 commented 2 years ago

A quick dirty fix up to make things work:

Change File "/usr/lib/python3.10/site-packages/pygments/formatters/terminal256.py", line 282 ttype.parent back to ttype[:-1] will work again.

Tae-juss commented 2 years ago

Thank you for looking into this @amjith. Does the following help?

2022-01-10 06:31:01,812 (70/MainThread) mycli.main ERROR - sql: 'select id from bag limit 1;', error: AttributeError("'str' object has no attribute 'parent'") 2022-01-10 06:31:01,813 (70/MainThread) mycli.main ERROR - traceback: 'Traceback (most recent call last):\n File "/usr/local/lib/python3.8/site-packages/pygments/formatters/terminal256.py", line 261, in format_unencoded\n on, off = self.style_string[str(ttype)]\nKeyError: \'Token.Output.TableSeparator\'\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n File "/usr/local/lib/python3.8/site-packages/mycli/main.py", line 711, in one_iteration\n formatted = self.format_output(\n File "/usr/local/lib/python3.8/site-packages/mycli/main.py", line 1029, in format_output\n formatted = self.formatter.format_output(\n File "/usr/local/lib/python3.8/site-packages/cli_helpers/tabular_output/output_formatter.py", line 168, in format_output\n data, headers = f(data, headers, column_types=column_types, *fkwargs)\n File "/usr/local/lib/python3.8/site-packages/cli_helpers/tabular_output/tabulate_adapter.py", line 170, in style_output\n newfmt = tabulate.TableFormat((addColorInElt(val) for val in srcfmt))\n File "/usr/local/lib/python3.8/site-packages/cli_helpers/tabular_output/tabulate_adapter.py", line 170, in \n newfmt = tabulate.TableFormat((addColorInElt(val) for val in srcfmt))\n File "/usr/local/lib/python3.8/site-packages/cli_helpers/tabular_output/tabulate_adapter.py", line 160, in addColorInElt\n return tabulate.Line(\n File "/usr/local/lib/python3.8/site-packages/cli_helpers/tabular_output/tabulate_adapter.py", line 161, in \n (style_field(table_separator_token, val) for val in elt)\n File "/usr/local/lib/python3.8/site-packages/cli_helpers/tabular_output/tabulate_adapter.py", line 153, in style_field\n formatter.format(((token, field),), s)\n File "/usr/local/lib/python3.8/site-packages/pygments/formatters/terminal256.py", line 250, in format\n return Formatter.format(self, tokensource, outfile)\n File "/usr/local/lib/python3.8/site-packages/pygments/formatter.py", line 94, in format\n return self.format_unencoded(tokensource, outfile)\n File "/usr/local/lib/python3.8/site-packages/pygments/formatters/terminal256.py", line 282, in format_unencoded\n ttype = ttype.parent\nAttributeError: \'str\' object has no attribute \'parent\'\n' 2022-01-10 06:31:03,277 (70/MainThread) mycli.main ERROR - sql: 'select id from bag limit 1', error: AttributeError("'str' object has no attribute 'parent'") 2022-01-10 06:31:03,277 (70/MainThread) mycli.main ERROR - traceback: 'Traceback (most recent call last):\n File "/usr/local/lib/python3.8/site-packages/pygments/formatters/terminal256.py", line 261, in format_unencoded\n on, off = self.style_string[str(ttype)]\nKeyError: \'Token.Output.TableSeparator\'\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n File "/usr/local/lib/python3.8/site-packages/mycli/main.py", line 711, in one_iteration\n formatted = self.format_output(\n File "/usr/local/lib/python3.8/site-packages/mycli/main.py", line 1029, in format_output\n formatted = self.formatter.format_output(\n File "/usr/local/lib/python3.8/site-packages/cli_helpers/tabular_output/output_formatter.py", line 168, in format_output\n data, headers = f(data, headers, column_types=column_types, *fkwargs)\n File "/usr/local/lib/python3.8/site-packages/cli_helpers/tabular_output/tabulate_adapter.py", line 170, in style_output\n newfmt = tabulate.TableFormat((addColorInElt(val) for val in srcfmt))\n File "/usr/local/lib/python3.8/site-packages/cli_helpers/tabular_output/tabulate_adapter.py", line 170, in \n newfmt = tabulate.TableFormat((addColorInElt(val) for val in srcfmt))\n File "/usr/local/lib/python3.8/site-packages/cli_helpers/tabular_output/tabulate_adapter.py", line 160, in addColorInElt\n return tabulate.Line(\n File "/usr/local/lib/python3.8/site-packages/cli_helpers/tabular_output/tabulate_adapter.py", line 161, in \n (style_field(table_separator_token, val) for val in elt)\n File "/usr/local/lib/python3.8/site-packages/cli_helpers/tabular_output/tabulate_adapter.py", line 153, in style_field\n formatter.format(((token, field),), s)\n File "/usr/local/lib/python3.8/site-packages/pygments/formatters/terminal256.py", line 250, in format\n return Formatter.format(self, tokensource, outfile)\n File "/usr/local/lib/python3.8/site-packages/pygments/formatter.py", line 94, in format\n return self.format_unencoded(tokensource, outfile)\n File "/usr/local/lib/python3.8/site-packages/pygments/formatters/terminal256.py", line 282, in format_unencoded\n ttype = ttype.parent\nAttributeError: \'str\' object has no attribute \'parent\'\n'

Tae-juss commented 2 years ago

I can't trigger the error locally. Can you tell me what is the data type of the id column?

The data type of id column is int

Also, just wanted to share that this worked without any issues until Thursday, 6th Jan 2022. Started getting this error from 7th Jan.

For some context, mycli is not a default requirement on the container. Hence, we only install it via pip whenever it's needed.

yegetables commented 2 years ago

快速修复以使事情正常进行:

将文件“/usr/lib/python3.10/site-packages/pygments/formatters/terminal256.py”,第 282 行更改 ttype.parentttype[:-1]将再次起作用。

yes, it can solve my problem.

rrain7 commented 2 years ago

pygments/pygments#2027

thank you, it can work.

jeffreytse commented 2 years ago

You can downgrade your pygments package to settle this issue temporarily.

pip install "pygments<=2.11.0"
amjith commented 2 years ago

A new version has been released with the pygments version pinned.

Tae-juss commented 2 years ago
pip install "pygments<=2.11.0"

Thank you! This worked for me :)

premnathwani commented 2 years ago

@Tae-juss: Thanks for reporting and @amjith: Thanks for quickly resolving.

Saved my day.