Skip to content

Commit

Permalink
add warning for overwrite channel (#2020)
Browse files Browse the repository at this point in the history
  • Loading branch information
ApostolFet authored Jan 6, 2025
1 parent d16fecf commit 258683e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 11 deletions.
27 changes: 18 additions & 9 deletions faststream/specification/asyncapi/v2_6_0/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,25 @@ def get_broker_channels(
channels = {}

for h in broker._subscribers:
# TODO: add duplication key warning
channels.update({
key: Channel.from_sub(channel) for key, channel in h.schema().items()
})

for key, channel in h.schema().items():
if key in channels:
warnings.warn(
f"Overwrite channel handler, channels have the same names: `{key}`",
RuntimeWarning,
stacklevel=1,
)
channels[key] = Channel.from_sub(channel)

for p in broker._publishers:
# TODO: add duplication key warning
channels.update({
key: Channel.from_pub(channel) for key, channel in p.schema().items()
})
for key, channel in p.schema().items():
if key in channels:
warnings.warn(
f"Overwrite channel handler, channels have the same names: `{key}`",
RuntimeWarning,
stacklevel=1,
)

channels[key] = Channel.from_pub(channel)

return channels

Expand Down
15 changes: 13 additions & 2 deletions faststream/specification/asyncapi/v3_0_0/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,13 @@ def get_broker_channels(
channel_obj = Channel.from_sub(sub_key, sub_channel)

channel_key = clear_key(sub_key)
# TODO: add duplication key warning
if channel_key in channels:
warnings.warn(
f"Overwrite channel handler, channels have the same names: `{channel_key}`",
RuntimeWarning,
stacklevel=1,
)

channels[channel_key] = channel_obj

operations[f"{channel_key}Subscribe"] = Operation.from_sub(
Expand All @@ -177,7 +183,12 @@ def get_broker_channels(
channel_obj = Channel.from_pub(pub_key, pub_channel)

channel_key = clear_key(pub_key)
# TODO: add duplication key warning
if channel_key in channels:
warnings.warn(
f"Overwrite channel handler, channels have the same names: `{channel_key}`",
RuntimeWarning,
stacklevel=1,
)
channels[channel_key] = channel_obj

operations[channel_key] = Operation.from_pub(
Expand Down

0 comments on commit 258683e

Please sign in to comment.