question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Getting error `'str' object has no attribute 'parent'`

See original GitHub issue

Description

Getting error 'str' object has no attribute 'parent' for any command that I run

Your environment

  • Please provide your OS and version information. Manjaro Linux
  • Please provide your CLI version. 3.2.0
  • What is the output of pip freeze command. I’m using pgcli inside of a virtual environment (in a directory called /dev/data/pytools/pgcli, and /dev/data/pytools/pgcli/pip freeze gives the following output:
cli-helpers==2.2.0
click==8.0.3
configobj==5.0.6
pendulum==2.1.2
pgcli==3.2.0
pgspecial==1.13.0
prompt-toolkit==3.0.24
psycopg2==2.9.3
Pygments==2.11.2
python-dateutil==2.8.2
pytzdata==2020.1
setproctitle==1.2.2
six==1.16.0
sqlparse==0.4.2
tabulate==0.8.9
wcwidth==0.2.5

I enabled DEBUG logging for pgcli, and I see the following trace back:

2022-01-06 09:27:37,241 (589351/MainThread) pgcli.main ERROR - traceback: 'Traceback (most recent call last):
  File "/data/dev/pytools/pgcli/lib/python3.10/site-packages/pygments/formatters/terminal256.py", line 261, in format_unencoded
    on, off = self.style_string[str(ttype)]
KeyError: 'Token.Output.TableSeparator'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/data/dev/pytools/pgcli/lib/python3.10/site-packages/pgcli/main.py", line 668, in execute_command
    output, query = self._evaluate_command(text)
  File "/data/dev/pytools/pgcli/lib/python3.10/site-packages/pgcli/main.py", line 939, in _evaluate_command
    formatted = format_output(title, cur, headers, status, settings)
  File "/data/dev/pytools/pgcli/lib/python3.10/site-packages/pgcli/main.py", line 1483, in format_output
    formatted = formatter.format_output(cur, headers, **output_kwargs)
  File "/data/dev/pytools/pgcli/lib/python3.10/site-packages/cli_helpers/tabular_output/output_formatter.py", line 168, in format_output
    data, headers = f(data, headers, column_types=column_types, **fkwargs)
  File "/data/dev/pytools/pgcli/lib/python3.10/site-packages/cli_helpers/tabular_output/tabulate_adapter.py", line 170, in style_output
    newfmt = tabulate.TableFormat(*(addColorInElt(val) for val in srcfmt))
  File "/data/dev/pytools/pgcli/lib/python3.10/site-packages/cli_helpers/tabular_output/tabulate_adapter.py", line 170, in <genexpr>
    newfmt = tabulate.TableFormat(*(addColorInElt(val) for val in srcfmt))
  File "/data/dev/pytools/pgcli/lib/python3.10/site-packages/cli_helpers/tabular_output/tabulate_adapter.py", line 160, in addColorInElt
    return tabulate.Line(
  File "/data/dev/pytools/pgcli/lib/python3.10/site-packages/cli_helpers/tabular_output/tabulate_adapter.py", line 161, in <genexpr>
    *(style_field(table_separator_token, val) for val in elt)
  File "/data/dev/pytools/pgcli/lib/python3.10/site-packages/cli_helpers/tabular_output/tabulate_adapter.py", line 153, in style_field
    formatter.format(((token, field),), s)
  File "/data/dev/pytools/pgcli/lib/python3.10/site-packages/pygments/formatters/terminal256.py", line 250, in format
    return Formatter.format(self, tokensource, outfile)
  File "/data/dev/pytools/pgcli/lib/python3.10/site-packages/pygments/formatter.py", line 94, in format
    return self.format_unencoded(tokensource, outfile)
  File "/data/dev/pytools/pgcli/lib/python3.10/site-packages/pygments/formatters/terminal256.py", line 282, in format_unencoded
    ttype = ttype.parent
AttributeError: 'str' object has no attribute 'parent'

Not sure what happened TBH. It was working before and suddenly I’m getting the error


UPDATE: after investigating, the issue seems to come from the latest release 2.11.2 from pygments. Downgrading to 2.11.1 removes the error

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:9
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
noppacommented, Jan 10, 2022

For anyone coming to this who’d just like a temporary workaround so they can run some queries with pgcli–the expanded display still works. You can switch to it with \x.

0reactions
amjithcommented, Jan 11, 2022

@Anteru I see your comment on the PR. I’ll take a stab at fixing it in cli_helpers.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Don't understand this AttributeError:'str' object has no attribute ...
I am making an application that will allow to display a running text in the window, but just started to parse the OOP,...
Read more >
AttributeError: 'str' object has no attribute 'parent' #518 - GitHub
Hi! When I want to validate my yang files using pyang 2.1 or 2.0.1 (didn't yet test on other versions) I get a...
Read more >
AttributeError: 'str' object has no attribute in Python | bobbyhadz
The Python AttributeError: 'str' object has no attribute occurs when we try to access an attribute that doesn't exist on string objects.
Read more >
Solve the attributeerror str object has no attribute decode error
This attribute error occurs because you are trying to call the decode() function on a Python string object, which is by default already...
Read more >
A class is considered as a string in python - Reddit
hey, to explain the problem- i have a variable, which a class named node and when ... AttributeError: 'str' object has no attribute...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found