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

jcroteau/APPEALS-44282 - Fix Deprecation Warning: NOT conditions will no longer behave as NOR in Rails 6.1. (dev) #21472

Conversation

jcroteau
Copy link
Contributor

@jcroteau jcroteau commented Apr 26, 2024

Resolves: https://jira.devops.va.gov/browse/APPEALS-44282

Background

DEPRECATION WARNING: NOT conditions will no longer behave as NOR in Rails 6.1

General Warning

DEPRECATION WARNING: NOT conditions will no longer behave as NOR in Rails 6.1.

Specific Example

DEPRECATION WARNING: NOT conditions will no longer behave as NOR in Rails 6.1. To continue using NOR conditions, NOT each condition individually (`.where.not(:decision_mailed => ...).where.not(:appeal_cancelled => ...)`). (called from perform at /opt/caseflow-certification/src/app/jobs/quarterly_notifications_job.rb:19)

Deprecation Horizon: Rails 6.1

Example

Rails 6.0

where.not with multiple conditions behaves like logical NOR

AppealState.where.not(decision_mailed: true, appeal_cancelled: true).to_sql
DEPRECATION WARNING: NOT conditions will no longer behave as NOR in Rails 6.1. To continue using NOR conditions, NOT each condition individually (`.where.not(:decision_mailed => ...).where.not(:appeal_cancelled => ...)`). (called from <main> at (pry):1)
SELECT "appeal_states".*
FROM "appeal_states"
WHERE "appeal_states"."decision_mailed" != TRUE AND "appeal_states"."appeal_cancelled" != TRUE
Rails 6.1

where.not with multiple conditions behaves like logical NAND

AppealState.where.not(decision_mailed: true, appeal_cancelled: true).to_sql
SELECT "appeal_states".*
FROM "appeal_states"
WHERE NOT ("appeal_states"."decision_mailed" = TRUE AND "appeal_states"."appeal_cancelled" = TRUE)

Affected Locations

RegEx Search: /\.not\b/

app/queries/etl/unknown_status_with_open_root_task_query.rb:24

# app/queries/etl/unknown_status_with_open_root_task_query.rb

def appeal_ids_for_open_child_tasks  
  ETL::Task.select(:appeal_id).distinct  
    .where(appeal_type: "Appeal")  
    .where.not(task_type: "RootTask", task_status: Task.closed_statuses)  
end

app/queries/etl/unknown_status_with_completed_root_task_query.rb:24

# app/queries/etl/unknown_status_with_completed_root_task_query.rb

def appeal_ids_for_open_child_tasks  
  ETL::Task.select(:appeal_id).distinct  
    .where(appeal_type: "Appeal")  
    .where.not(task_type: "RootTask", task_status: Task.closed_statuses)  
end

app/models/vbms_uploaded_document.rb:13

# app/models/vbms_uploaded_document.rb

scope :successfully_uploaded, lambda {  
  where(error: nil).where.not(uploaded_to_vbms_at: nil, attempted_at: nil, processed_at: nil)  
}

app/jobs/quarterly_notifications_job.rb:19

# app/jobs/quarterly_notifications_job.rb

AppealState.where.not(  
  decision_mailed: true, appeal_cancelled: true  
)

Proposed Solution

Rewrite each of the affected ActiveRecord queries above to preserve existing NOR behavior:

Example

BEFORE fix

Query with where.not having multiple conditions behaves like logical NOR but triggers deprecation warning.

AppealState.where.not(decision_mailed: true, appeal_cancelled: true).to_sql
DEPRECATION WARNING: NOT conditions will no longer behave as NOR in Rails 6.1. To continue using NOR conditions, NOT each condition individually (`.where.not(:decision_mailed => ...).where.not(:appeal_cancelled => ...)`). (called from <main> at (pry):1)
SELECT "appeal_states".*
FROM "appeal_states"
WHERE "appeal_states"."decision_mailed" != TRUE AND "appeal_states"."appeal_cancelled" != TRUE

AFTER fix

Query with multiple, chainedwhere.not relations, each on a single condition, preserves logical NOR and no longer triggers deprecation warning.

AppealState.where.not(decision_mailed: true).where.not(appeal_cancelled: true).to_sql
SELECT "appeal_states".*
FROM "appeal_states"
WHERE "appeal_states"."decision_mailed" != TRUE AND "appeal_states"."appeal_cancelled" != TRUE 

Jira Test Plan: https://jira.devops.va.gov/browse/APPEALS-45156

Refactors affected queries to address the following deprecation warning
in anticipation of Rails 6.1:

    DEPRECATION WARNING: NOT conditions will no longer behave as NOR in Rails 6.1.
    To continue using NOR conditions, NOT each condition individually
    (`.where.not(:task_type => ...).where.not(:task_status => ...)`).
Copy link

Code Scanning Policy Findings

Your repository contains unresolved code scanning alerts. Policy requires that all code scanning alerts of critical severity be resolved within 30 days.

In the future, if your repository contains unresolved code scanning alerts older than 30 days, you will not be able to merge this pull request.

Learn more about how to triage and remediate these alerts in the GitHub Code Scanning documentation.

If this pull request remediates these alerts, after your pull requests CodeQL scan has completed, follow this link to re-run the policy check and select Re-run all jobs at the top of the page: https://github.com/department-of-veterans-affairs/caseflow/actions/runs/8852846432

You may also re-run this required check by simply commenting on this pull request with the following command:
/actions-bot rerun-required-workflows

Alert NumberURLAgePolicy Violation
24Link400 DaysYes
20Link403 DaysYes
19Link403 DaysYes
18Link403 DaysYes

Copy link

codeclimate bot commented Apr 26, 2024

Code Climate has analyzed commit c16d3d5 and detected 0 issues on this pull request.

View more on Code Climate.

@jcroteau jcroteau marked this pull request as ready for review April 26, 2024 21:22
@jcroteau
Copy link
Contributor Author

Released in #21629

@jcroteau jcroteau closed this May 17, 2024
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.

2 participants