Problem/Motivation
XeroItemManager::doLoadItem() adds a query condition to query an item by its guid.
According to https://community.xero.com/developer/question/43161
You would be better off not using a 'WHERE' if you are retrieving a contact and know the GUID already:
GET https://…/Contacts/{identifier}
Steps to reproduce
\Drupal::service('xero.item_manager')->loadItem('xero_account', '12633dc2-
6fa3-4995-b96f-4215e88dc8f9');
leads to a logged error from Xero, a QueryParseException:
Operator '==' incompatible with operand types 'Guid' and 'String'
Proposed resolution
Load by guid directly, without a WHERE.
Remaining tasks
I'll prepare a patch.
User interface changes
None.
API changes
None.
Data model changes
None.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | 3179866-2.patch | 29.51 KB | jonathanshaw |
Issue fork xero-3179866
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
jonathanshawSo I did the following:
1) In xeroQuery use Contacts/{$this->uuid} as the endpoint rather than just Contacts, any time the id is set on the query.
2) Adapt XeroItemManager::loadItem to set the id on the query rather than specifiy a condition.
3) In which case XeroItemManager::doLoadItem is uneeded, reloadItem() can just wrap loadItem() now.
4) Added a XeroQueryExecuteTest kernel test. It's not much now, but it's a step in a good direction. Unit tests are masochistic when woring with typed data.
5) I also tidied up the createGuid helper method. It was being duplicated a dozen times, sometimes with the optional $braces argument ignored, and sometimes tests were even depending on it being ignored. Given that history of confusion, I thought it best to split into 2 methods, createGuid() and (more rarely used) createGuidWithBraces().
6) As this helper is needed by both kernel and unit tests, I created a Traits directory and put a XeroGuidTrait there.
7) I removed Unit/XeroTestHelperTrait and replaced with with XeroGuidTrait and XeroTokenTrait
Comment #3
jonathanshawComment #6
mradcliffeRe-rolled patch in #2 and then added an example to xero_example module mainly for manual testing.
I think all the changes should be there.
Comment #7
mradcliffeIssue status ping-pong to see if merge request will run tests after I forgot to enable test on issues.
Comment #8
mradcliffeBack to needs review.
Comment #9
jonathanshawReroll looks good to me, thanks for looking at this.
Comment #10
johnpitcairn commentedAha. Was wondering why I couldn't query for a bank transaction by its guid.
[edit: removed irrelevant problem]
Comment #11
johnpitcairn commentedThis appears to be working as expected, and fixes a major annoyance.
Comment #13
mradcliffeThank you for the review, @jonathanshaw. Thank you for the review and testing, @John Pitcairn. I'm sorry for my tardiness.
Merging in now.