-
Notifications
You must be signed in to change notification settings - Fork 2
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
fix: Get allowlist answers from both breadcrumb data and answers #2838
Conversation
Removed vultr server and associated DNS entries |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an awesome solution @DafyddLlyr 🥳
I think there's just a small tweak required to get the output from getAnswers
and getData
to match.
I also tried adding some variables to the ALLOW_LIST
which are all set by the same component and it worked as anticipated handling setting multiple keys 🙌
I think it's out of scope of this but I think the recent work has shown that node_fn
isn't a valuable column although I think it could be useful at some point to add a ticket to rename it to passport_variables
and maybe set it? Could be really useful for debugging automations etc.
One other thing which might be worth checking if how this change might impact the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for fixing this @DafyddLlyr
Testing locally this commit has done the trick 🥳
const answerValues = answerIds.map((answerId) => flow[answerId]?.data?.val); | ||
|
||
// Match data structure of `allow_list_answers` column | ||
const answers = [ {[nodeFn]: answerValues } ]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having a brief look at the analytics_logs
I think as the data structure there'll now be a mismatch between current and old data i.e. array of values vs array of objects:
Although seeing as we haven't been tracking allow_list_list
I wonder if we can just crack on?
Otherwise I think it would be possible to update historical data using the node_fn
value as the key 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep - good point. First thought would be to ignore this as it's a new column, however having data in different formats in the column would prove tricky to query so we might as well do this properly!
There's more logs populated than expected already on production, so I think clearing older logs is not really a solution here.
I've tested the following SQL locally which will convert the column. Could you please review and manually test the SQL below @Mike-Heneghan before we run on production (once this change has gone to prod).
To select rows with the "old" data format -
SELECT
id,
node_fn,
node_type,
allow_list_answers
FROM
analytics_logs
WHERE
jsonb_typeof(allow_list_answers) = 'array'
AND jsonb_typeof(allow_list_answers -> 0) = 'string';
And then this to update "old" → "new" -
UPDATE analytics_logs
SET allow_list_answers = (
SELECT jsonb_agg(jsonb_build_object(key, value))
FROM (
SELECT
node_fn AS key,
jsonb_array_elements_text(allow_list_answers) AS value
FROM analytics_logs
WHERE jsonb_typeof(allow_list_answers) = 'array' AND
jsonb_typeof(allow_list_answers->0) = 'string'
) AS subquery
)
WHERE jsonb_typeof(allow_list_answers) = 'array' AND
jsonb_typeof(allow_list_answers->0) = 'string';
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ha! That doesn't match my results - I maybe just had a simple use case 😅 Let me take another look!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries! This sort of stuff is really fiddly, please let me know when you want me to retest 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I get it sorry - I'm just testing on a single record 🤦
Probably just needs and id=id clause. Taking a look and thanks for testing!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey sorry for the slow turnaround here @Mike-Heneghan
Clause added and highlighted with comment -
UPDATE analytics_logs
SET allow_list_answers = (
SELECT jsonb_agg(jsonb_build_object(node_fn, subquery.values))
FROM (
SELECT jsonb_agg(value) AS values
FROM (
SELECT
node_fn,
jsonb_array_elements_text(allow_list_answers) AS value
FROM analytics_logs inner_log
WHERE
-- New clause to match ids
inner_log.id = analytics_logs.id AND
jsonb_typeof(inner_log.allow_list_answers) = 'array' AND
jsonb_typeof(inner_log.allow_list_answers->0) = 'string'
) AS subquery_inner
) AS subquery
)
WHERE
jsonb_typeof(allow_list_answers) = 'array' AND
jsonb_typeof(allow_list_answers->0) = 'string';
Getting expected results here, but as always would love another pair of eyes 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah perfect - honestly thanks again for being so on-point with testing here, really helped! 🙌
Follow up from #2835 following comments from @Mike-Heneghan
What does this PR do?
drawBoundary.action
)proposal.projectType
)allow_list_answers
column will be in the format[ {nodeFn} : answers ]
allow_list_answers
for session summary tablefn
field of the component won't match the variable used in the allow list (e.g.drawBoundary.userAction
which is set automatically by the component)I'd love to get some tests written for analytics as my previous PR inadvertently caused a breaking regression which was missed. I think this should be fairly stable going forward so let's wait and see on this one, but it's likely a good idea before the next set of potentially breaking changes 🤞