-
Notifications
You must be signed in to change notification settings - Fork 0
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
Decouple decidim api client from the decidim lv_state object #48
Comments
Hmm, I see what you mean about needing a custom query... but I think preparing a graphql query on decidim's side also defeats the purpose of using the ruby client. We can pair on this when the time comes, to try and find a way to encapsulate that in the client while building the decidim-specific state in decidim |
Yes, I don't like the custom query too much. The idea was to leave the four mutator queries, that's the api for any LV client using ruby-client gem. The decidim code would use those four, plus fall back to passing graphql string for the current state, but right now it seems we should be able to provide a current state query and supporting ruby struct in a generic, non-decidim way. Pairing is perfect. |
I started a discussion #66 for how to do this. |
Hey guys, to expedite things, I'm settling on the solution proposed on #66 (comment): # lib/decidim/liquidvoting.rb
module Decidim
module Liquidvoting
# previously part of the api client
def user_proposal_state(user_email, proposal_url)
# Talks to the api through the client
end
# previously on Decidim's Proposal model
def update_vote_count(proposal)
# Saves to the db using activerecord's update_column()
end
end
end We can iterate on this later if we aren't happy with it after the change. |
Summarizing from a call just now with Oliver: We agree to the three boundaries he outlines in the conversation:
We can make We agreed it's not worth spending a lot of time here, so if this extraction gets messy we'll talk again. |
Adding a I think we should 1) move the update call into the helper, and 2) still override the original |
That's a good question. But in the end we can already see that in the logs, if it gets called (the sql query is already logged), and locking our module to a given decidim version ensures no new surprise decidim code will be added. The cleanest and less defensive thing is to ensure all calls to This also reminds me we should instrument both our decidim instance and our module to post events and logs to Honeycomb. I'll add an issue for that |
However, it's wrapped in an For me, it seems high risk to lose the LV count until the next api mutation results in it being corrected. The safest way would be to make the method a no-op, but lmk what you think. I think it also better communicates to anyone looking at the code that LV has taken ownership of that attribute. Edit: the proposal I'm making is to 1) override |
Hm, the callback context does complicate things. Adding the no-op is still unsafe, imo, because if it is called, it means we've missed a scenario where we should be calling LV instead, and the count will be inconsistent because of that. And it defeats the purpose of neatly isolating the change: we'd still be changing the proposal model, and adding a new way of doing things at the same time, adding complexity. If we're changing the model, we might as well leave the change there, covering for unforeseen scenarios that the callback covers. There's another issue we need to double check, as well - is the proposal model used in other places besides supports and endorsements, in, say, initiatives or assemblies? One way to map out where |
I'm thinking how hard it's going to be to debug if we have unexpected One approach is to 1) keep logging, 2) run the full spec suite, 3) see what shows in the log. I think this can work if we keep a discipline to redo this exercise each time we bump decidim gems. Let's call this a "decidim version verification" process, a list of things to do when we bump gems. My first instinct was to put a Maybe we can log specifically enough to surface the event with our instrumentation: when it happens, we're alerted. That might be a |
failing / raising works to trace this in the test suite 👍 I didn't quite get what you meant about not trusting verification 😄 And your last sentece was cut off I think we should: 1 - use fail / raise locally to roughly trace where the method gets called Feel free to make the method noop if it makes you more comfortable, but in the end it'll give us inconsistent results anyway. So the only way forward is to detect where it's still called progressively, and replace the call with LV calls. With time we should have this covered for a given Decidim version. |
Ah, for not trusting: I meant inspecting to find callers, and remembering to do it again when bumping Decidim gems. It felt too informal for what would be a difficult bug to find. I no longer like the no-op approach, you're right it's the same problem in either case...let's do a best-effort (via I'm finishing the refactor today, and I'll open a separate issue for doing and documenting this best-effort to find Decidim callers of |
I think the best we can do is incrementally detect the calls over time, and we'll eventually have a good grasp. I expect upgrading will also be easier than the first time around.
ok :)
Makes sense, good call 👍 |
In
client.rb
we have both api client code, and support for retrieving a current LV state object.Since we want to align with ruby-client, which is independent of any integration, we need to separate these two things. Also, we will eventually replace
client.rb
with a gem.One approach might be to have non-
client.rb
code pass a graphql query string to ageneric_query
method insideclient.rb
, and wrap the result in a state struct.The text was updated successfully, but these errors were encountered: