Repository navigation
Align the vendored McritClient with MCRIT 1.15.0's client - #45
Conversation
The vendored client matched MCRIT 1.12.0's. This mirrors what changed in mcrit/client/McritClient.py between v1.12.0 and v1.15.0 for every method the plugin keeps: - A 200 or 202 whose body is not JSON, such as a proxy's login page or an empty answer, is a failed answer: None by default, McritServerError under raise_server_errors, with a log warning. A body that is not a dict is failed too. It used to raise a JSON decoding error in every mode (mcrit#258). - awaitResult raises the new JobFailedError, with the job id and the queue's last_error, when a job ends without a result, instead of requesting /results/None. JobTerminatedError still comes first. Job.last_error tolerates a job that never recorded an error, as in core (mcrit#255). - modifyFamily takes actors and sends the update as JSON, since a list does not survive form encoding, and answers the Response in raw mode (mcrit#177). - The matching requests take shortlist_size, band_df_cutoff and preset. The sample-vs-sample and cross comparisons take no shortlist_size, as a shortlist ranked over the corpus could only drop the samples they name (mcrit#217). - getJobCount and deleteQueueData pass their criteria as params, so requests encodes them (mcrit#236). - isFunctionId loses a raw-mode branch it could never reach, and getFunctionById returns the raw Response before handling it, as core does. - addBinarySample documents that its query fields are passed through as given. The one requests.Session per client (mcrit#254) was already in place. getSampleBinary, requestBandDfCutoffCoverage and deleteOrphanedQueueFiles are outside the plugin's trimmed surface and stay out. modifyFamily, modifySample and both binary match requests also raised TypeError on every call: they passed the request body positionally to the client's _put and _post wrappers, which take it only by keyword. The bodies now go as json= or data=, matching what requests.put and requests.post did with them in core. Each mirrored behaviour has a test in tests/core/test_mcrit_client.py; the new ones fail against the previous client.
danielplohmann
left a comment
There was a problem hiding this comment.
Thanks, this matches core. I compared the methods it touches against v1.15.0 (d4de94a): handle_response, awaitResult with JobFailedError, modifyFamily with actors as JSON, the three matching knobs (left out of the sample-vs-sample and cross compares, as in core), the encoded getJobCount/deleteQueueData params, and the raw-mode order in isFunctionId/getFunctionById. The data= in modifySample and the binary queries is what core's positional body means to requests, so the ### Fixed entry is right.
On the plugin side: nothing calls awaitResult, so JobFailedError cannot reach plugin code. Nothing relied on the old ValueError from a non-JSON 2xx either. The plugin runs in the default mode, so such an answer is now None plus a logged warning.
Merged onto the current main (with #36 and #38), CHANGELOG.md merges cleanly in the order Added / Changed / Fixed. Lint, the sync checks and the suite (288 tests) pass. Against the old client, test_mcrit_client.py does not even import.
Closes #43.
The vendored client in
mcrit_plugin/core/minimcrit/client/McritClient.pymatched MCRIT 1.12.0's since #30. This mirrorsgit diff v1.12.0 v1.15.0 -- mcrit/client/McritClient.py(v1.15.0 isd4de94a) for every method the plugin keeps.What changes
Noneby default,McritServerErrorunderraise_server_errors, with a log warning. A body that is not a dict is failed too.awaitResultraisesJobFailedError(job_id, last_error)for a job that ends without a result, instead of requesting/results/None.JobTerminatedErrorstill comes first.Job.last_erroruses.get(), as in core, so a job that never errored hasNone.modifyFamily(..., actors=None)sends JSON and answers the Response in raw mode.shortlist_size,band_df_cutoffandpreset. The sample-vs-sample and cross comparisons take noshortlist_size, as in core.getJobCountanddeleteQueueDatapass their criteria asparams, so they are encoded._job_selection_queryalready was.requests.Sessionper client was already there since #34. Nothing diverged.isFunctionIdloses a raw-mode branch it could never reach.getFunctionByIdnow returns the raw Response before handling it, as core does, so raw mode with a raising mode no longer raises.Left out:
getSampleBinary(mcrit#95),requestBandDfCutoffCoverageanddeleteOrphanedQueueFilesare outside the plugin's trimmed surface, as agreed in #28.Also fixed:
modifyFamily,modifySample,requestMatchesForMappedBinaryandrequestMatchesForUnmappedBinaryraisedTypeErroron every call. They passed the request body positionally to the client's_put/_postwrappers, which only take keyword arguments. The plugin calls none of them, which is how this went unnoticed. The bodies now go asjson=ordata=, which is whatrequests.put/requests.postdid with them in core. This has its own### Fixedentry in the changelog.I compared the two clients method by method after normalising formatting, annotations, docstrings and the plugin's
_get/_postwrappers. The only differences left are equivalent forms: keyword instead of positional arguments,data=where core passes the body positionally,_search_basebuilt inline where core has a_search_requesthelper, and the unique-block params built inline.Testing
tests/core/test_mcrit_client.pyhas a test for each mirrored behaviour. The tests use realrequests.Responseobjects and check the prepared URLs for the encoding. 23 of them fail against the previous client; the rest guard behaviour that is unchanged.getMatchesForSamplewith all three knobs, which reached the job asgetMatchesForSample(0, 50, 10, 1, 50, 1000), andawaitResultreturned its result;ruff format --check,ruff check,run_quality_checks.py, the sync checks andpython -m pytest tests(266 tests) pass.