Skip to content
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

Merged
merged 12 commits into from
Aug 10, 2023
Merged

Fix:1802 project summary bug #1815

merged 12 commits into from
Aug 10, 2023

Conversation

@BCerki BCerki force-pushed the 1802-project-summary-bug branch 3 times, most recently from 70b12df to 85d1cc2 Compare July 24, 2023 20:18
Comment on lines +21 to 22
reporting_requirement_record_id := fc.form_data_record_id;

Copy link
Collaborator Author

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.

"projectId":1,
"reportType": "General Milestone",
"reportingRequirementIndex": 1
}'::jsonb, 'milestone'::varchar),
('{
(4,6,'{
Copy link
Collaborator Author

@BCerki BCerki Jul 24, 2023

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

Copy link
Contributor

@Sepehr-Sobhani Sepehr-Sobhani left a 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.

Comment on lines 355 to 386
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 '======';


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leftover!

@BCerki BCerki force-pushed the 1802-project-summary-bug branch 2 times, most recently from 47cc522 to 7970d7f Compare July 31, 2023 17:26
@BCerki
Copy link
Collaborator Author

BCerki commented Jul 31, 2023

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.

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.

dleard
dleard previously requested changes Aug 4, 2023
Copy link
Contributor

@dleard dleard left a 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;

Copy link
Contributor

@Sepehr-Sobhani Sepehr-Sobhani left a 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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🫣

@BCerki
Copy link
Collaborator Author

BCerki commented Aug 8, 2023

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

Copy link
Contributor

@Sepehr-Sobhani Sepehr-Sobhani left a 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 🤩

Comment on lines 178 to 181
console.log("emissions");
console.log("allFormChangesPristine", allFormChangesPristine);
console.log("viewOnly", viewOnly);
console.log("summaryReportingRequirement", summaryReportingRequirement);
Copy link
Contributor

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);
Copy link
Contributor

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);
Copy link
Contributor

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leftover!

Comment on lines 36 to 41
-- 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);
Copy link
Contributor

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?

Copy link
Collaborator Author

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!

Copy link
Contributor

@Sepehr-Sobhani Sepehr-Sobhani left a 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();
Copy link
Contributor

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.

@BCerki BCerki merged commit 55379bd into develop Aug 10, 2023
15 of 16 checks passed
@BCerki BCerki deleted the 1802-project-summary-bug branch August 10, 2023 20:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants