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.

User comments in config file lost after writing to config via `pgcli`

See original GitHub issue

Description

First of all, thanks for a great tool, I use it a lot.

User comments to the pgcli config file are getting lost after the config file gets modified via pgcli itself (e.g. adding a named query). According to https://github.com/dbcli/pgcli/issues/1162#issuecomment-740076796 they should remain. Additionally, all whitelines from at least the [named queries] section onward get lost as well.

I can reproduce this on a clean virtualenv and with a fresh config file.

Reproduce

Log from my reproduction attempts:

  • Removed previous config file
  • Created new temp virtualenv (using the system Python 3.6.9), installed new pgcli (pip install pgcli)
  • Started pgcli, this created a new config file
  • Config file (from [named queries] section onward; same goes for the config file snippets below) at this point:
    # Named queries are queries you can execute by name.
    [named queries]
    
    # DSN to call by -D option
    [alias_dsn]
    # example_dsn = postgresql://[user[:password]@][netloc][:port][/dbname]
    
    # Format for number representation
    # for decimal "d" - 12345678, ",d" - 12,345,678
    # for float "g" - 123456.78, ",g" - 123,456.78
    [data_formats]
    decimal = ""
    float = ""
    
  • Save new named query from pgcli: \ns foo bar. Config file snippet after this:
    [named queries]
    foo = bar
    [alias_dsn]
    [data_formats]
    decimal = ""
    float = ""
    
    • NOTE: the “# Named queries are queries you can execute by name.” comment (and the preceding whiteline) above the [named query] section header is now gone as well (while the “# style classes for colored table output” comment above output.header = "#00ff5f bold" remained in tact. As did all other comment and whitelines earlier in the file)
  • Close pgcli (just in case), add user comment above the foo = bar named query entry. Config file snippet after this:
    [named queries]
    # My comment
    foo = bar
    [alias_dsn]
    [data_formats]
    decimal = ""
    float = ""
    
  • Start pgcli again, add new named query: \ns bar SELECT 1. Config file snippet after this:
    [named queries]
    foo = bar
    bar = SELECT 1
    [alias_dsn]
    [data_formats]
    decimal = ""
    float = ""
    
  • Close pgcli (just in case), add record and comment to [alias_dsn]. Config file snippet after this:
    [named queries]
    foo = bar
    bar = SELECT 1
    [alias_dsn]
    # I feel like I'm getting lost
    baz = postgresql://foo@localhost/postgres
    [data_formats]
    decimal = ""
    float = ""
    
  • Start pgcli again, add new named query: \ns baz SELECT 2. Config file snippet after this:
    [named queries]
    foo = bar
    bar = SELECT 1
    baz = SELECT 2
    [alias_dsn]
    baz = postgresql://foo@localhost/postgres
    [data_formats]
    decimal = ""
    float = ""
    

Did another quick test (only some of the steps from above) with a Python 3.9.0 (via pyenv) temp virtualenv, same results. Tried this one with both a pip install pgcli and a pip install git+https://github.com/dbcli/pgcli@master.

The same happens in my proper config file using my proper pgcli install, which contains many more named queries and DSN aliases.

Environment, verison info

  • OS: Ubuntu 18.04.5 (x64)

  • pgcli:

    • In most of the tests above:
      Server: PostgreSQL 9.6.13
      Version: 3.1.0
      
    • My proper install:
      Version: 3.0.0
      
  • pip freeze of my proper install:

``` cffi==1.14.0shared libraries cli-helpers==1.2.1 click==7.1.1 configobj==5.0.6 cryptography==2.9.2 dbus-python==1.2.16 humanize==2.3.0 importlib-metadata==1.7.0 jeepney==0.4.3 keyring==21.2.1 pgcli==3.0.0 pgspecial==1.11.9 pkg-resources==0.0.0 prompt-toolkit==3.0.8 psycopg2==2.8.5 pycparser==2.20 Pygments==2.6.1 SecretStorage==3.1.2 setproctitle==1.1.10 six==1.14.0 sqlparse==0.3.1 tabulate==0.8.7 terminaltables==3.1.0 wcwidth==0.1.9 zipp==3.1.0 ```

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:12 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
j-bennetcommented, Feb 27, 2021

I submitted a PR into ConfigObj repo. We’ll see what happens with that.

https://github.com/DiffSK/configobj/pull/212

0reactions
j-bennetcommented, Mar 1, 2021

Fixed via https://github.com/dbcli/pgcli/pull/1251.

This is by no means a perfect solution. I wish that configparser in stdlib supported comments on write, unfortunately it does not. I’d like to try and submit a PR to https://github.com/DiffSK/configobj to fix this issue, but it will not happen immediately.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Configuration - pgcli
Most of pgcli's user settings are configured via the file located at ~/.config/pgcli/config , which is a hidden file in your home folder...
Read more >
comments are getting deleted while updating the web config ...
1 Answer 1 ... There is not way to maintain the comments. It is how .NET implemented it. But you can have your...
Read more >
PostgreSQL is running locally but I cannot connect. Why?
I had mis-configured the listening port in the config file: /etc/postgresql/9.4/main/postgres.conf. I had changed the port from port = 5432 to port =...
Read more >
16.4. Run-time Configuration - PostgreSQL
When a password is specified in CREATE USER or ALTER USER without writing either ENCRYPTED or UNENCRYPTED, this option determines whether the password...
Read more >
dbcli/pgcli - Gitter
@judu The config file is located under `~/.config/pgcli/config. If you'd like to add support for some missing features please file an issue and...
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