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

Only return valid models from get_loaded_model_by_path #801

Merged
merged 2 commits into from
May 18, 2020

Conversation

macobo
Copy link
Contributor

@macobo macobo commented Apr 24, 2020

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.

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.
Copy link
Collaborator

@drwl drwl left a comment

Choose a reason for hiding this comment

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

Thanks for contributing this patch!

@drwl drwl merged commit 27e5965 into ctran:develop May 18, 2020
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.
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