karafka-testing icon indicating copy to clipboard operation
karafka-testing copied to clipboard

`karafka.produce` fails validation due to` {:topic=>"does not match the topic allowed format"}` if `karafka.consumer_for` hasn't been called

Open technicalpickles opened this issue 11 months ago • 0 comments

To make this process smoother for everyone involved, please read the following information before filling out the template.

Scope of the OSS Support

We do not provide OSS support for outdated versions of Karafka and its components.

Please ensure that you are using a version that is still actively supported. We cannot assist with any no longer maintained versions unless you support us with our Pro offering (https://karafka.io/docs/Pro-Support/).

We acknowledge that understanding the specifics of your application and its configuration can be essential for resolving certain issues. However, due to the extensive time and resources such analysis can require, this may fall beyond our Open Source Support scope.

If Karafka or its components are critical to your infrastructure, we encourage you to consider our Pro Offering.

By backing us up, you can gain direct assistance and ensure your use case receives the dedicated attention it deserves.

Important Links to Read

Please take a moment to review the following resources before submitting your report:

  • Issue Reporting Guide: https://karafka.io/docs/Support/#issue-reporting-guide
  • Support Policy: https://karafka.io/docs/Support/
  • Versions, Lifecycle, and EOL: https://karafka.io/docs/Versions-Lifecycle-and-EOL/

Bug Report Details

I started using karafka.produce to produce some messages, but I started getting a failure like:

     WaterDrop::Errors::MessageInvalidError:
       {:topic=>"does not match the topic allowed format"}
     # ./karafka-testing-repro.rb:9:in `block (2 levels) in <main>'
     # -e:1:in `<main>'

It seems that this happens if you haven't called karafka.consumer_for before karafka.produce.

Additional Context

Reproducible case:

RSpec.describe 'karafka testing repro' do
  it 'works' do
    payload = {
      foo: 'bar',
      baz: 1,
    }
    karafka.produce(payload.to_json)
  end
end

Output with --backtrace

❯ bin/rspec karafka-testing-repro.rb --backtrace
Running via Spring preloader in process 6307

Randomized with seed 2582
F

Failures:

  1) karafka testing repro works
     Failure/Error: karafka.produce(payload.to_json)
     
     WaterDrop::Errors::MessageInvalidError:
       {:topic=>"does not match the topic allowed format"}
     # /Users/josh.nichols/.local/share/mise/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/karafka-core-2.4.5/lib/karafka/core/contractable/contract.rb:109:in `validate!'
     # /Users/josh.nichols/.local/share/mise/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/waterdrop-2.7.4/lib/waterdrop/producer.rb:266:in `validate_message!'
     # /Users/josh.nichols/.local/share/mise/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/waterdrop-2.7.4/lib/waterdrop/producer/sync.rb:20:in `produce_sync'
     # /Users/josh.nichols/.local/share/mise/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/karafka-testing-2.4.6/lib/karafka/testing/rspec/helpers.rb:156:in `_karafka_produce'
     # /Users/josh.nichols/.local/share/mise/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/karafka-testing-2.4.6/lib/karafka/testing/rspec/proxy.rb:21:in `produce'
     # ./karafka-testing-repro.rb:9:in `block (2 levels) in <main>'
  
Finished in 0.096 seconds (files took 3 seconds to load)
1 example, 1 failure

Failed examples:

rspec ./karafka-testing-repro.rb:4 # karafka testing repro works

Randomized with seed 2582

technicalpickles avatar Dec 10 '24 16:12 technicalpickles