-
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:1802 project summary bug #1815
Conversation
70b12df
to
85d1cc2
Compare
reporting_requirement_record_id := fc.form_data_record_id; | ||
|
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 line was missing and that's what created the bug. This function returns reporting_requirement_record_id
, so if we don't assign here, then the update and archive cases return null.
85d1cc2
to
8451e31
Compare
"projectId":1, | ||
"reportType": "General Milestone", | ||
"reportingRequirementIndex": 1 | ||
}'::jsonb, 'milestone'::varchar), | ||
('{ | ||
(4,6,'{ |
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.
If the commit handler returns null, then the form_data_record_id
is also null. So when create_project_revision
makes a copy of the existing forms, it just copies the original one over and over again instead of getting the latest one. Testing that form_data_record_id
is correct here should ensure the bug is fixed
8451e31
to
a2973f6
Compare
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 looks great! However, I do have one concern. There are currently three projects in production that have an associated project summary report, but the values in the database are incorrect. To resolve this issue, I believe we should create a migration and commit the form changes related to those projects.
Will share Project IDs in the MS Teams channel.
select '-----------'; | ||
select form_data_record_id, previous_form_change_id, new_form_data, json_schema_name from cif.form_change | ||
where form_data_table_name = 'reporting_requirement' and project_revision_id = 2 | ||
order by form_data_record_id; | ||
select '-----------'; | ||
|
||
select '-----------'; | ||
select form_data_record_id, previous_form_change_id, new_form_data | ||
from cif.form_change | ||
where form_data_record_id = 4 | ||
and form_data_schema_name = 'cif' | ||
and form_data_table_name = 'reporting_requirement' | ||
and json_schema_name='project_summary_report' | ||
and change_status = 'committed' | ||
order by updated_at desc, id desc; | ||
-- limit 1; | ||
select '-----------'; | ||
|
||
select '======'; | ||
select id, | ||
operation , | ||
form_data_schema_name, | ||
form_data_table_name, | ||
form_data_record_id , | ||
project_revision_id , | ||
change_status , | ||
json_schema_name, | ||
validation_errors , | ||
previous_form_change_id from cif.form_change where json_schema_name='project_summary_report'; | ||
select '======'; | ||
|
||
|
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.
Leftover!
47cc522
to
7970d7f
Compare
I've written a migration to add the missing form_data_record_ids to the existing projects so that any new revisions of these projects will have the latest data. However, I think there might be a little manual reconstruction for the CIF team because the latest data isn't necessarily complete. |
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.
Looks good, just one suggestion to make and we need a migration to call the migration function. Make sure to disable these 3 triggers in the migration file:
_100_committed_changes_are_immutable
_set_previous_form_change_id,
_100_timestamps;
schema/deploy/functions/migration_rebuild_project_summary_report_history.sql
Outdated
Show resolved
Hide resolved
2cf3e7a
to
34db13c
Compare
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.
Looks good to me! There are only two minor changes needed.
@@ -0,0 +1,85 @@ | |||
|
|||
begin; | |||
select no_plan(); |
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.
🫣
schema/test/unit/functions/migration_rebuild_project_summary_report_history_test.sql
Show resolved
Hide resolved
I think I fixed the bug about the summary report summary not showing in view. I found another related one that wasn't straightforward so I made a card: https://app.zenhub.com/workspaces/climate-action-secretariat-60ca4121764d710011481ca2/issues/gh/bcgov/cas-cif/1844 |
Co-authored-by: Dylan Leard <[email protected]>
764421c
to
00246c4
Compare
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.
I did notice a few leftovers and have one small question. Can you please help me with that?
Otherwise, everything seems to be in order 🤩
console.log("emissions"); | ||
console.log("allFormChangesPristine", allFormChangesPristine); | ||
console.log("viewOnly", viewOnly); | ||
console.log("summaryReportingRequirement", summaryReportingRequirement); |
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.
Leftover!
@@ -223,7 +226,7 @@ const ProjectEmissionsIntensityReportFormSummary: React.FC<Props> = ({ | |||
}, | |||
}, | |||
}; | |||
|
|||
console.log("allFormChangesPristine", allFormChangesPristine); |
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.
Leftover!
}) => { | ||
console.log("query", query); |
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.
Leftover!
`, | ||
query | ||
); | ||
console.log("projectSummaryReportFormBySlug", projectSummaryReportFormBySlug); |
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.
Leftover!
-- all updates have the same previous_form_change_id=1 and form_data_record_id=123 (bug=form_data_record_id clears on commit) | ||
select cif.create_form_change('update', 'project_summary_report', 'cif', 'project_summary_report', '{"description": "value"}', 123, 1, 'pending', '[]'); | ||
|
||
select cif.create_form_change('update', 'project_summary_report', 'cif', 'project_summary_report', '{"description": "most recent"}', 123, 1, 'pending', '[]'); | ||
|
||
select cif.commit_project_revision(1); |
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.
Now that you've resolved the problem with the summary report handler, I'm wondering if we can be certain that the commit handler will clear the form_data_record_id upon commit. Do you think it would be better to simply pass null values for form_data_record_id instead?
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.
Great point, thanks for catching this!
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.
Awesome 🤩
select '-----'; | ||
select * from cif.form_change order by id asc; | ||
select '-----'; | ||
select cif_private.migration_rebuild_project_summary_report_history(); |
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.
I think we should still keep this line! sorry for the hassle.
card: https://app.zenhub.com/workspaces/climate-action-secretariat-60ca4121764d710011481ca2/issues/gh/bcgov/cas-cif/1802