get_loaded_model_by_path is supposed to be nil-safe#883
Merged
ctran merged 1 commit intoctran:developfrom Jun 14, 2021
sato11:restore-nil-safety
Merged
get_loaded_model_by_path is supposed to be nil-safe#883ctran merged 1 commit intoctran:developfrom sato11:restore-nil-safety
get_loaded_model_by_path is supposed to be nil-safe#883ctran merged 1 commit intoctran:developfrom
sato11:restore-nil-safety
Conversation
This commit partially reverts #801, which by declaring conditional return has turned `get_loaded_model_by_path` to a less safe method that can return nil when its the condition is not met. Apparently the very same condition has been brought to `annotate_model_file` by #774, which seems to cover the "bug" insisted in #801 as well. On the other hand #801 has brought an inconvenient behaviour as well: whenever a non-activerecord model file is found, `get_loaded_model_by_path` returns nil, which leads to raising `BadModelFileError` and ends up printing a bunch of "Unable to annotate ..." messages. Now it seems tests added by #801 are running right and I do not find a problem restoring the previous behaviour and turn it nil-safe again.
Contributor
Author
Owner
|
I'll take a look at the CI configuration. You want this to be merged for 3.1.2 right? |
Contributor
Author
|
Yes I do since v3.1.2 would introduce breaking change if shipped without this. Thanks for the quick action! 🙌 |
ocarta-l
pushed a commit
to ocarta-l/annotate_models
that referenced
this pull request
Jun 18, 2021
This commit partially reverts ctran#801, which by declaring conditional return has turned `get_loaded_model_by_path` to a less safe method that can return nil when its the condition is not met. Apparently the very same condition has been brought to `annotate_model_file` by ctran#774, which seems to cover the "bug" insisted in ctran#801 as well. On the other hand ctran#801 has brought an inconvenient behaviour as well: whenever a non-activerecord model file is found, `get_loaded_model_by_path` returns nil, which leads to raising `BadModelFileError` and ends up printing a bunch of "Unable to annotate ..." messages. Now it seems tests added by ctran#801 are running right and I do not find a problem restoring the previous behaviour and turn it nil-safe again.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This commit partially reverts #801, which by declaring conditional return
has turned
get_loaded_model_by_pathto a less safe method that canreturn nil when its condition is not met.
Apparently the very same condition has been brought to
annotate_model_fileby #774, which seems to cover the "bug" insisted in #801 as well.
On the other hand #801 has brought an inconvenient behaviour as well:
whenever a non-activerecord model file is found,
get_loaded_model_by_pathreturns nil, which leads to raising
BadModelFileErrorand ends upprinting a bunch of "Unable to annotate ..." messages.
Now it seems tests added by #801 are running right and I do not find
a problem restoring the previous behaviour and turn it nil-safe again.
Say we have a file like
app/models/foo/bar.rbwhich is NOT a subclass of ActiveRecord::Base:We do not want this to get annotated but the current code does give it a try, ending up showing a bunch of error messages like this:
With this change the behaviour in v3.1.1 is restored and these un-informational errors are gone.