-
-
Notifications
You must be signed in to change notification settings - Fork 825
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
APIv4 - Use correct BAO delete function (fixes dev/core#2757) #21232
Conversation
(Standard links)
|
607c368
to
5378555
Compare
@eileenmcnaughton I'd say based on the previous test run on this PR that there is existing test coverage. I messed up the |
I think the test fail relates @colemanw api.v4.Entity.ConformanceTest.testConformance with data set "Contact" (from api_v4_Entity_ConformanceTest__testConformance) Stacktraceapi\v4\Entity\ConformanceTest::testConformance with data set "Contact" ('Contact') Entity "Contact" was not deleted Failed asserting that 1 matches expected 0. |
Got it passing @eileenmcnaughton ! |
@colemanw I tested this and it still fails - #21137 - the reason is that apiv3 (but not v4 with this PR) deletes a contact in accordance with the sites trash policy unless the api caller forces it to hard-delete. I think that is actually the right approach - ie the default should be delete to trash. Separately (& probably out of scope) I think a change could be made to the deletecontact to better handled related memberships when deleting to trash - but that's a bit more wonky since the UI forces soft delete first so the process is already done |
Whew that's a tough one @eileenmcnaughton. We have a few different entities with an But to address your concern, what do you think about these options:
The 3rd option is of course my favorite because it doesn't involve any work on my part, but I understand you might feel differently :) |
The conflict makes sense to me if I imagine two different kinds of development tasks:
With
Here's a variation on
|
This is the newest aspect of an ongoing, bigger question. It has probably been discussed publicly somewhere at some point, but I'm not aware of it. The question is, what should the API do, in a broad sense? Should the API perform all the same business logic that gets performed when actions are taken in the UI? Or should it be a lean, clean CRUD machine -- essentially a 1:1 SQL wrapper with no business logic? In CiviCRM, "save" often doesn't just mean save -- it often means "process the input depending on various factors, save the resulting entity, and possibly create/update/delete several linked entities". And, more relevant to the discussion here, "delete/deleted" means various things in various places, as @colemanw mentions. This business logic -- a pretty thick (and sometimes convoluted) layer between input and database -- is a big part of what makes Civi smart (and it can also make devels tear their hair out when they need to make a customization). In working with API3 and now API4, I've gotten the impression that the answer to "what should the API do?" has changed. Version 3 seemed to include business logic in its "CRUD" operations, at least sometimes, and version 4 seems to be avoiding that as much as possible. API4 conforms much more tightly to the shape of the MySQL database layer, using a structure borrowed directly from SQL where feasible. As I understand it, this is an attempt "to reduce ambiguity and improve flexibility and consistency" as stated in the docs. Again, sorry if I'm re-treading old ground in this wordy post. But it seems worthwhile to ask what our guiding principle is. (@eileenmcnaughton, @colemanw or others, can you link to that if it exists?) If it's to make the API as transparent and internally consistent as possible, then "delete" should always mean, literally, "delete". A separate "move to trash" action could be provided. That's probably my preferred solution (Coleman's option 1 above). And maybe we should consider that it's the UI that's ambiguous! On sites where "trash/undelete" is enabled, we could change the UI: instead of a "Delete Contact" button, call it "Move to Trash". |
To be clear, while there are some things I like about API4 being a thinner layer over the database, it would also be great if it provided access to the complex logic that's present in the application. What I'm advocating is for those to be clearly separate actions. I think we should avoid overloading a small set of actions with a bunch of flags that switch their behavior. |
Aaaand, when spoke out against flag-switches just now, I hadn't read @totten's idea -- which actually sounds like a justifiable use of a flag 🎏 |
Ok, I've combined the suggestions from @eileenmcnaughton and @totten and myself into this: This does represent a change to APIv4, as the default behavior is now
|
Retest this please |
Prompted by @eileenmcnaughton's helpful dev digest... @totten I didn't understand
Are those listed in respective order? I'm assuming not. And does "optional" mean "use trash if supported by the entity"? @colemanw @highfalutin +1 for your idea re the business logic. I think an API first aproach is really helpful, and that UIs should use those APIs. I too like that API4 feels "lower level"/more SQL like. I'd like the basic CRUD to be pretty low level and other actions to expose higher level business stuff, but I guess it will always be a balance/bit blurred. |
Params are camelCase, fields are snake_case, and |
On reflection, I feel like adding a dummy The standard for APIv4 to-date is that it's very strict about enforcing params, and I'm hesitant to start relaxing that due to problems that don't yet exist. My vote would be to merge this as-is. |
@eileenmcnaughton I still feel this is merge-ready, and the status-quo behavior that it fixes is very very wrong. |
@colemanw - I finally re-visited this with a bit of headspace and I agree with the conclusion you came to. This is consistent with the v3 api & UI and like the v3 api & BAO there is an option to force delete. I don't think the discussion above is blocking. I did notice a couple of things
I think this is mergeable - will re-run tests (test this please) and let you re-check the above but giving merge-ready |
Uses BAO::del() only if it isn't deprecated.
This sets Contact::delete to move contacts to the trash by default.
@eileenmcnaughton I've rebased this and also added the missing annotation so the param is discoverable in the IDE. |
@colemanw OK - & it's been a couple more days so anyone who wanted to scream could have - merging |
@colemanw I do think we want something in docs still |
@eileenmcnaughton I've added it to the changelog |
@colemanw ok - but in this case I was more imaging in the api docs since it's a behaviour people probably need to understand. Ah well win some |
@eileenmcnaughton let me know where to add it and I'll write something |
@highfalutin maybe under the delete action? https://docs.civicrm.org/dev/en/latest/api/v4/actions/ - but I'd be interested to see where you think you would look to find it too |
@eileenmcnaughton that's where I'd look, along with the explorer and my IDE. https://lab.civicrm.org/documentation/docs/dev/-/merge_requests/977 |
thanks @highfalutin !!! |
Overview
Fixes the contact delete bug noted in dev/core#2757 and gives us a way to noisy-deprecate
BAO::del()
functions without tripping up APIv4 tests.