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 single table inheritance deprecation warning bug #84

Merged

Conversation

zarembas
Copy link
Contributor

@zarembas zarembas commented Aug 21, 2023

This fix prevents the deprecation warning Entities was manually included in a model from being raised when using single table inheritance. The warning was being raised because the DfE::Analytics::Entities module gets included in all the entity model classes.

I noticed we were still getting deprecation warnings after this PR got merged: DFE-Digital/apply-for-teacher-training#8374

DEPRECATION WARNING: DfE::Analytics::Entities was manually included in a model (ApplicationWorkExperience), but it's included automatically since v1.4. You're running v1.10.1. To silence this warning, remove the include from model definitions in app/models.
DEPRECATION WARNING: DfE::Analytics::Entities was manually included in a model (ApplicationVolunteeringExperience), but it's included automatically since v1.4. You're running v1.10.1. To silence this warning, remove the include from model definitions in app/models.
DEPRECATION WARNING: DfE::Analytics::Entities was manually included in a model (TextCondition), but it's included automatically since v1.4. You're running v1.10.1. To silence this warning, remove the include from model definitions in app/models.
DEPRECATION WARNING: DfE::Analytics::Entities was manually included in a model (SkeCondition), but it's included automatically since v1.4. You're running v1.10.1. To silence this warning, remove the include from model definitions in app/models.
DEPRECATION WARNING: DfE::Analytics::Entities was manually included in a model (ReferenceCondition), but it's included automatically since v1.4. You're running v1.10.1. To silence this warning, remove the include from model definitions in app/models.

Looking into the code it seems that once the first include runs, all the following classes in that group already have the model included. I initially thought that it gets included in the parent class, but that doesn't seem to be the case.

> mfes = models_for_entity(entity)

> mfes[0].include?(DfE::Analytics::Entities)
=> false
> mfes[1].include?(DfE::Analytics::Entities)
=> false
> mfes[2].include?(DfE::Analytics::Entities)
=> false

> mfes[0].include(DfE::Analytics::Entities)

> mfes[0].include?(DfE::Analytics::Entities)
=> true
> mfes[1].include?(DfE::Analytics::Entities)
=> true
> mfes[2].include?(DfE::Analytics::Entities)
=> true

> mfes[0].superclass
=> ApplicationRecord(abstract)

> mfes[0].superclass.include?(DfE::Analytics::Entities)
=> false

I also removed the @shown_deprecation_warning instance variable as it wasn't serving any purpose.

Tagging @duncanjbrown @JR-G here as I don't have access to this repo

This fix prevents the deprecation warning `Entities was manually
included in a model` from being raised when using single table
inheritance. The warning was being raised because the
`DfE::Analytics::Entities` module gets included in all the entity
model classes.
Copy link
Contributor

@duncanjbrown duncanjbrown left a comment

Choose a reason for hiding this comment

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

Thank you!

@zarembas
Copy link
Contributor Author

FYI I don't have access to this repo, so I can't merge the PR.

@duncanjbrown duncanjbrown merged commit 6d42dc0 into DFE-Digital:main Aug 29, 2023
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