FIX: Read the resource key in the failure to match example the way the others do - #350
Conversation
…ery other example does The example read only the older 'resource_key' variable, so a reader who had set _51DEGREES_RESOURCE_KEY, which the other examples and this repository's own CI use, was told to create a resource key. It now asks ExampleUtils, which reads both names, and a test runs the example with the current name alone.
Proven in CIFull build and test run on this branch: https://github.com/51Degrees/device-detection-python/actions/runs/35190436789 A draft pull request only runs the link lint, so the Pull Requests workflow was dispatched against this branch as a dry run to get real evidence. Nothing was merged, and the log shows why: with no pull request based on this branch the run builds the branch on its own as pull request 0, and the checkout and completion steps both print "Not running for a PR". All 19 jobs finished green, being 15 build and test jobs (Python 3.10, 3.11, 3.12, 3.13 and 3.14 on Ubuntu, Windows and macOS), the pull request lookup, the configure step, the performance comparison and the completion step. Reading the job logs rather than the conclusions, each of the 15 build and test jobs reports 89 tests passed, the same on every platform and every version, and no failures. Searching the whole log for "Failed!", "FAILURES" and a non-zero failed count finds nothing. The pull request has not been marked ready and no review has been requested. |
Problem
cloud/failuretomatch.pyread the resource key from theresource_keyenvironment variable alone. Every other example in this package reads it
through
ExampleUtils.get_resource_key(), which looks at_51DEGREES_RESOURCE_KEYfirst and falls back to the older name, andci/run-integration-tests.ps1sets_51DEGREES_RESOURCE_KEYfor thatreason.
So a reader who had set the current name, and could run every other cloud
example, was told by this one to create a resource key.
Nothing caught it, because this is the one cloud example with no test.
The other five are covered by
tests/test_cloudexamples.py.What changed
cloud/failuretomatch.pyasksExampleUtilsfor the key and printsExampleUtils.get_missing_resource_key_message()when there is none,so it answers to the same variable names as the rest and names the
variable it wanted. The link to the configurator share is kept, on one
line, because the campaign lint reads a line at a time.
tests/test_cloudexamples.pyruns the example as a script with thecurrent variable set and the older one removed, and checks that it does
not report a missing key, that it prints its answer, and that none of
the fault markers the other example tests look for appears.
Verification
pytest tests/test_cloudexamples.py -k failuretomatchwith a bespokeresource key: passes. Against the example as it was, the same test
fails on "No resource key found".
_51DEGREES_RESOURCE_KEYalone it answersTruethenFalsefor thetwo User-Agents, with
resource_keyalone it does the same, and withneither it names the variable to set.
pytest tests/test_cloudexamples.pywith a bespoke key: 4 passed, 2failed. The two failures are
taclookup_consoleandnativemodellookup_console, which need the hardware product that notest key carries, and they fail the same way on main.
utm-lint.ps1 -Campaign device-detection-pythonis clean.Outstanding
available, which is an entitlement matter rather than a code one.
Sibling change
The PHP repository has a fault in the same example, although a different
one, in
device-detection-php#74.
There the failure to match example wrote its built pipeline to a file and
reused it on the next run, so a run with one resource key answered with the
properties of whichever key had run first. Neither change depends on the
other.
CI
The "Pull Requests" workflow was dispatched on this branch with
dryrun=true. Run35164298813
passed on all 15 build and test jobs. It ran on commit
4ae4bac5, and theonly later commit,
a9c7dff0, adds one blank line between two tests, sothe head commit itself carries the UTM link lint check alone. Anyone
wanting a check on the head commit will have to dispatch the workflow
again.
Still to do elsewhere
readme.mdandfiftyone_devicedetection_examples/readme.mdstill tell areader to set
resource_key, which is the older name. Both stay correct,because
ExampleUtilsreads that name as a fallback, but they do not name_51DEGREES_RESOURCE_KEYat all. That is a separate piece of work and isnot touched here.
Taken out of draft on 17 September 2026
The paragraph above asking for a run on the head commit has now been done.
Run 35190436789
is on the head commit
a9c7dff, a dispatch of the Pull Requests workflowwith
dryrunset, and all 19 jobs passed. The job logs show the examplesuites running rather than being skipped, at 5 passed with 8 skipped, then
51 passed, then 14 passed, then 19 passed, and the Selenium contract tests
reporting
Failed: 0, Passed: 9.The branch is level with
main, so nothing needed merging in.Still outstanding, and it does not stop this merging. The two hardware
examples named above cannot be run with any key CI has, which is an
entitlement matter rather than a code one, and they fail the same way on
main.