Skip to content

User comments in config file lost after writing to config via pgcli #1240

@ghost

Description

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 #1162 (comment) 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:

Details ``` 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 ```

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions