Skip to content
This repository has been archived by the owner on Sep 23, 2024. It is now read-only.

added statement_timeout to connection_config #73

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

alamirfan
Copy link

Problem

Getting this error in tap-postgres. psycopg2.errors.QueryCanceled: canceling statement due to statement timeout

Proposed changes

Added statement_timeout in connection config so that if it is provided then the connection will be held for long time.

Types of changes

What types of changes does your code introduce to PipelineWise?
Put an x in the boxes that apply

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation Update (if none of the other choices apply)

Checklist

  • Description above provides context of the change
  • I have added tests that prove my fix is effective or that my feature works
  • Unit tests for changes (not needed for documentation changes)
  • CI checks pass with my changes
  • Bumping version in setup.py is an individual PR and not mixed with feature or bugfix PRs
  • Commit message/PR title starts with [AP-NNNN] (if applicable. AP-NNNN = JIRA ID)
  • Branch name starts with AP-NNN (if applicable. AP-NNN = JIRA ID)
  • Commits follow "How to write a good git commit message"
  • Relevant documentation is updated including usage instructions

tap_postgres/db.py Outdated Show resolved Hide resolved
tap_postgres/db.py Outdated Show resolved Hide resolved
@@ -49,6 +49,10 @@ def open_connection(conn_config, logical_replication=False):
'connect_timeout': 30
}

statement_timeout = conn_config.get('statement_timeout')
if statement_timeout is not None:
cfg['options'] = f'-c statement_timeout={statement_timeout}s'
Copy link
Contributor

@koszti koszti Jan 13, 2021

Choose a reason for hiding this comment

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

this is cool, but can we try making it more generic and prepare it somehow to accept any valid postgres options?

What if we introduce a new options key in config.json:

{
  "host": "x", 
  "port": "x",
  "user": "x",
  "password": "x",
  "dbname": "x",
  "options": [
    "statement_timeout=60s",
    "another_option=120",
    "and_another_option=180"
  ]
} 

And in the code it would be something like this:

cfg['options'] = ' '.join(map('-c {0}'.format, conn_config.get('options',[])))

what do you think?

Copy link
Author

Choose a reason for hiding this comment

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

PR Updated

Copy link
Contributor

@koszti koszti Jan 13, 2021

Choose a reason for hiding this comment

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

thanks, how we want to deal with the case if the options key in the config.json is not a list but a string or a number? Can we raise an exception with a meaningful error message in that case?

Adding some sort of unit test for open_connection would be great as well. Maybe we need to mock the psycopg2.connect ?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants