Only return valid models from get_loaded_model_by_path#801
Merged
drwl merged 2 commits intoctran:developfrom May 18, 2020
Merged
Only return valid models from get_loaded_model_by_path#801drwl merged 2 commits intoctran:developfrom
drwl merged 2 commits intoctran:developfrom
Conversation
This avoids cases where you have: ``` module Foobar; end; class A class Foobar; end end ``` And get_loaded_model returns Foobar even though it isn't the right thing to do. This was a case I ran into where the base module was autogenerated.
3af2d00 to
ade7582
Compare
drwl
approved these changes
May 18, 2020
Collaborator
drwl
left a comment
There was a problem hiding this comment.
Thanks for contributing this patch!
ctran
pushed a commit
that referenced
this pull request
Jun 14, 2021
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.
ocarta-l
pushed a commit
to ocarta-l/annotate_models
that referenced
this pull request
Jun 18, 2021
This is a bugfix for the following case: ``` # app/models/foo.rb module Foo; end # app/models/bar/foo.rb class Bar::Foo < Activerecord::Base; end ``` Where `Bar::Foo` would never get annotated.
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 is a bugfix for the following case:
Where
Bar::Foowould never get annotated.