Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit bd643a2

Browse filesBrowse files
authored
fix: correctly override question type flag for requests (#1558)
* fix: correctly override question type flag for requests Currently even when setting the explicit question type flag, the implementation ignores it for subsequent queries. This commit ensures that all queries respect the explicit question type flag. * chore(tests): add test for explicit question type flag Add unit test to validate that the explicit question type flag is set correctly in outgoing requests.
1 parent 94620b0 commit bd643a2
Copy full SHA for bd643a2

File tree

2 files changed

+22
-1
lines changed
Filter options

2 files changed

+22
-1
lines changed

‎src/zeroconf/_services/info.py

Copy file name to clipboardExpand all lines: src/zeroconf/_services/info.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,7 @@ async def async_request(
859859
if last <= now:
860860
return False
861861
if next_ <= now:
862-
this_question_type = question_type or QU_QUESTION if first_request else QM_QUESTION
862+
this_question_type = question_type or (QU_QUESTION if first_request else QM_QUESTION)
863863
out = self._generate_request_query(zc, now, this_question_type)
864864
first_request = False
865865
if out.questions:

‎tests/services/test_info.py

Copy file name to clipboardExpand all lines: tests/services/test_info.py
+21Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import zeroconf as r
1919
from zeroconf import DNSAddress, RecordUpdate, const
20+
from zeroconf._protocol.outgoing import DNSOutgoing
2021
from zeroconf._services import info
2122
from zeroconf._services.info import ServiceInfo
2223
from zeroconf._utils.net import IPVersion
@@ -1871,3 +1872,23 @@ async def test_address_resolver_ipv6():
18711872
aiozc.zeroconf.async_send(outgoing)
18721873
assert await resolve_task
18731874
assert resolver.ip_addresses_by_version(IPVersion.All) == [ip_address("fe80::52e:c2f2:bc5f:e9c6")]
1875+
1876+
1877+
@pytest.mark.asyncio
1878+
async def test_unicast_flag_if_requested() -> None:
1879+
"""Verify we try four times even with the random delay."""
1880+
type_ = "_typethatisnothere._tcp.local."
1881+
aiozc = AsyncZeroconf(interfaces=["127.0.0.1"])
1882+
1883+
def async_send(out: DNSOutgoing, addr: str | None = None, port: int = const._MDNS_PORT) -> None:
1884+
"""Sends an outgoing packet."""
1885+
for question in out.questions:
1886+
assert question.unicast
1887+
1888+
# patch the zeroconf send
1889+
with patch.object(aiozc.zeroconf, "async_send", async_send):
1890+
await aiozc.async_get_service_info(
1891+
f"willnotbefound.{type_}", type_, question_type=r.DNSQuestionType.QU
1892+
)
1893+
1894+
await aiozc.async_close()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.