Skip to content

Comments

Fix default port on secure connection + Query Parameterization#138

Open
barakor wants to merge 1 commit intolong2ice:devfrom
barakor:fix-default-port-on-secure
Open

Fix default port on secure connection + Query Parameterization#138
barakor wants to merge 1 commit intolong2ice:devfrom
barakor:fix-default-port-on-secure

Conversation

@barakor
Copy link

@barakor barakor commented May 21, 2025

I found and fixed 2 bugs:

  • when creating a secure Connection without specifying the port, it default to 9000 even though there's logic to handle it.
  • Query parameterization seemed broken, there where no tests and it was using a mix of methods for string formatting that doesn't mix (% formatting with dict as the specifier): I changed it to be inline with the functions logic (using .format() with a dict)

@barakor barakor changed the title Fix default port on secure connection Fix default port on secure connection + Query Parameterization May 21, 2025
@barakor barakor force-pushed the fix-default-port-on-secure branch from d7efd64 to ebfe24e Compare May 22, 2025 08:16
user = config.get("user", None) or user
password = config.get("password", None) or password
host = config.get("host", None) or host
port = config.get("port", None) or port
Copy link

Choose a reason for hiding this comment

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

What if it's secure and no port was specified?

Copy link
Author

Choose a reason for hiding this comment

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

this is what this pr is about, Protoconnection handles this already

Copy link

Choose a reason for hiding this comment

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

But it doesn't check secure from dsn and so port will always be constants.DEFAULT_PORT if it's not specified in dsn or maybe I don't understand something?

Copy link
Author

Choose a reason for hiding this comment

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

One of my changes was to add a check for secure from the dsn

Copy link

Choose a reason for hiding this comment

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

Python 3.12.10 (main, Apr  8 2025, 11:35:47) [GCC 14.2.1 20250322] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from asynch.proto import constants
>>> from asynch.proto.utils.dsn import parse_dsn
>>>
>>> dsn = 'clickhouses://user:pass@hostname/database'
>>> secure = False
>>> port = None
>>> if secure and port is None:
...     port = constants.DEFAULT_SECURE_PORT
... elif not secure and port is None:
...     port = constants.DEFAULT_PORT
...
>>> config = parse_dsn(dsn)
>>> user = config.get("user") or user
>>> password = config.get("password") or password
>>> host = config.get("host") or host
>>> port = config.get("port") or port
>>> database = config.get("database") or database
>>> secure = config.get("secure") or secure
>>> print(port, secure)
9000 True
>>>

@barakor barakor requested review from misuzu and stankudrow May 26, 2025 14:22
@stankudrow
Copy link
Contributor

@DaniilAnichin , @pohmelie, hello 👋 .

Could you possibly review this PR?

"stack_track": stack_track,
}

self._connection = ProtoConnection(**config, stack_track=stack_track, **kwargs)

Choose a reason for hiding this comment

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

Why we need stack_track=stack_track in the middle?

Copy link
Contributor

Choose a reason for hiding this comment

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

Based on what I see above, because stack_track is not part of dsn, so will be missing if we follow the first if branch above. Probably for same reason it was explicitly passed in prev version.

Choose a reason for hiding this comment

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

It should be excluded from config then, I think

Copy link
Contributor

@DaniilAnichin DaniilAnichin left a comment

Choose a reason for hiding this comment

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

Minor comment on styling on the port check, other than that lgtm

"stack_track": stack_track,
}

self._connection = ProtoConnection(**config, stack_track=stack_track, **kwargs)
Copy link
Contributor

Choose a reason for hiding this comment

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

Based on what I see above, because stack_track is not part of dsn, so will be missing if we follow the first if branch above. Probably for same reason it was explicitly passed in prev version.

@stankudrow
Copy link
Contributor

@barakor , hello. Any updates? Are you willing to drag this PR to the finish line?

@barakor
Copy link
Author

barakor commented Jun 18, 2025

hello. Any updates? Are you willing to drag this PR to the finish line?

What's missing @stankudrow ? I thought I addressed everything

@stankudrow
Copy link
Contributor

hello. Any updates? Are you willing to drag this PR to the finish line?

What's missing @stankudrow ? I thought I addressed everything

Added new suggestions and outlined the existent.

Also, is this case is implemented in a unit test?

tests and query params bug fix

fix bug with default port for secure connection

typing and moving function to module

Update asynch/proto/connection.py

Nones and such

Update test_escape.py

styling

Co-Authored-By: Stanley Kudrow <stankudrow@yandex.ru>
@barakor barakor force-pushed the fix-default-port-on-secure branch from bf3f6e0 to ef5fb97 Compare February 12, 2026 18:51
@barakor
Copy link
Author

barakor commented Feb 12, 2026

Rebased

@stankudrow
Copy link
Contributor

Rebased

Probably the PR #147 may be merged soon enough, feel free to have a look at it if you like.

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.

5 participants