Skip to content

Conversation

@cyrillkuettel
Copy link
Contributor

@cyrillkuettel cyrillkuettel commented Jan 6, 2026

Commit message

Core: Fix transfer command to use DSN connection parameters

The transfer command was using sudo -u postgres psql which connects
to the system postgres user's default instance instead of respecting
the onegov.yml DSN configuration. This allows to use ports other than
5432 locally. (Which is something you probably want to do to differentiate
between different PostgreSQL versions, if there are more than one installed.)

TYPE: Feature

Checklist

  • I considered adding a reviewer

The transfer command was using `sudo -u postgres psql` which connects
to the system postgres user's default instance instead of respecting
the onegov.yml DSN configuration. This allows to use ports other than
5432 locally.

TYPE: Bugfix
@codecov
Copy link

codecov bot commented Jan 6, 2026

Codecov Report

❌ Patch coverage is 3.12500% with 31 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.35%. Comparing base (03fc0ce) to head (3329351).
⚠️ Report is 8 commits behind head on master.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/onegov/core/cli/commands.py 3.12% 31 Missing ⚠️
Additional details and impacted files
Files with missing lines Coverage Δ
src/onegov/core/cli/commands.py 38.04% <3.12%> (-2.12%) ⬇️

... and 2 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 03fc0ce...3329351. Read the comment docs.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Member

@Daverball Daverball left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall, although there is a little bit of unnecessary parsing code duplication. Also there's a more robust way of setting an environment variable in a subprocess call.

Copy link
Member

@Daverball Daverball left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you need to care about the multi host part of MultiHostUrl, if you use the scalar properties they will return the first host. I also don't think we need to guard against empty hosts.

Comment on lines +701 to +712
hosts = local_dsn.hosts()
if hosts:
host_info = hosts[0]
local_host = host_info.get('host') or 'localhost'
local_port = str(host_info.get('port') or 5432)
local_user = host_info.get('username') or 'postgres'
local_password = host_info.get('password') or ''
else:
local_host = 'localhost'
local_port = '5432'
local_user = 'postgres'
local_password = '' # nosec: B105
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
hosts = local_dsn.hosts()
if hosts:
host_info = hosts[0]
local_host = host_info.get('host') or 'localhost'
local_port = str(host_info.get('port') or 5432)
local_user = host_info.get('username') or 'postgres'
local_password = host_info.get('password') or ''
else:
local_host = 'localhost'
local_port = '5432'
local_user = 'postgres'
local_password = '' # nosec: B105
local_host = local_dsn.host or 'localhost'
local_port = str(local_dsn.port or 5432)
local_user = local_dsn.username or 'postgres'
local_password = local_dsn.password or ''

I believe this should work out to exactly the same result, hosts is only necessary if you want to handle more than one host.

Comment on lines +504 to +515
hosts = local_dsn._url.hosts()
if hosts:
host_info = hosts[0]
local_host = host_info.get('host') or 'localhost'
local_port = str(host_info.get('port') or 5432)
local_user = host_info.get('username') or 'postgres'
local_password = host_info.get('password') or ''
else:
local_host = 'localhost'
local_port = '5432'
local_user = 'postgres'
local_password = '' # nosec: B105
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
hosts = local_dsn._url.hosts()
if hosts:
host_info = hosts[0]
local_host = host_info.get('host') or 'localhost'
local_port = str(host_info.get('port') or 5432)
local_user = host_info.get('username') or 'postgres'
local_password = host_info.get('password') or ''
else:
local_host = 'localhost'
local_port = '5432'
local_user = 'postgres'
local_password = '' # nosec: B105
local_host = local_dsn.host or 'localhost'
local_port = str(local_dsn.port or 5432)
local_user = local_dsn.username or 'postgres'
local_password = local_dsn.password or ''

Same thing here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants