Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Kafka backend): use enum values when represent kafka backend as d… #131

Merged

Conversation

marcosschroh
Copy link
Collaborator

@marcosschroh marcosschroh commented Sep 20, 2023

…ict. Close #130

Currently when a Kafka backend is created, enums are not properly represented causing errors when instantiating producers and consumers. We rely on backend.dict() to propagate the kafka configuration: producer instantiation and consumer instantiation

Example:

from kstreams.backends.kafka import  Kafka, SecurityProtocol

kafka_backend = Kafka(
    security_protocol=SecurityProtocol.SASL_PLAINTEXT,
    sasl_plain_username="username",
    sasl_plain_password="pwd",
)

kafka_backend.dict()

{
    'bootstrap_servers': ['localhost:9092'],
    'security_protocol': <SecurityProtocol.SASL_PLAINTEXT: 'SASL_PLAINTEXT'>,  # WRONG 
    'ssl_context': None,
    'sasl_mechanism': <SaslMechanism.PLAIN: 'PLAIN'>,    # WRONG 
    'sasl_plain_username': 'username',
    'sasl_plain_password': 'pwd',
    'sasl_oauth_token_provider': None
}

print(Kafka(sasl_mechanism='PLAIN').sasl_mechanism) 
# <SaslMechanism.PLAIN: 'PLAIN'>

This patch will fix the dict representation:

{
   'bootstrap_servers': ['localhost:9092'],
    'security_protocol': 'SASL_PLAINTEXT',  # Expected by aiokafka
    'ssl_context': None,
    'sasl_mechanism': 'PLAIN',  # Expected by aiokafka
    'sasl_plain_username': 'username',
    'sasl_plain_password': 'pwd',
    'sasl_oauth_token_provider': None
}


assert Kafka(sasl_mechanism='PLAIN').sasl_mechanism) == 'PLAIN'

@codecov
Copy link

codecov bot commented Sep 20, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.02% 🎉

Comparison is base (28a377d) 94.10% compared to head (f9823d0) 94.12%.
Report is 5 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #131      +/-   ##
==========================================
+ Coverage   94.10%   94.12%   +0.02%     
==========================================
  Files          20       20              
  Lines         712      732      +20     
==========================================
+ Hits          670      689      +19     
- Misses         42       43       +1     
Flag Coverage Δ
unittests 94.12% <100.00%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Changed Coverage Δ
kstreams/backends/kafka.py 96.07% <100.00%> (+0.07%) ⬆️

... and 1 file with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@marcosschroh marcosschroh merged commit af14c3f into kpn:master Sep 20, 2023
6 of 7 checks passed
@marcosschroh marcosschroh deleted the fix/use-enum-values-on-backed-as-dict branch September 20, 2023 13:57
marcosschroh added a commit to marcosschroh/kstreams that referenced this pull request Jun 18, 2024
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.

Enum encoded wrong in SASL handshake
3 participants