-
Notifications
You must be signed in to change notification settings - Fork 926
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
Trace import: remove activerecord-import gem #5038
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall the big difference between import!
and insert_all!
is that the former runs validations and the latter does not so maybe if we're going to change we should run validate!
on each point after it is created?
Really the ideal way to use insert_all!
would be not to build the models at all and just build a list of hashes but as it stands we need to run the save callbacks to fill in the tile number...
.rubocop.yml
Outdated
@@ -71,6 +71,7 @@ Rails/SkipsModelValidations: | |||
Exclude: | |||
- 'db/migrate/*.rb' | |||
- 'app/controllers/users_controller.rb' | |||
- 'app/models/trace.rb' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to exclude this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rubocop was complaining about the use of insert_all! because it's bypassing validations.
5733e21
to
3b138b6
Compare
669ffa8
to
3fe4399
Compare
3fe4399
to
781f6ec
Compare
The main reason I haven't merged this is that I can't make up my mind if I like it... I understand that in theory moving to the built-in version is good but then it turned out they're not equivalent really so we have to jump through hoops and disable cops and it just starts to smell a little. |
Well, we could disable rubocop's skip model validation check for that single line only, in case this would be an improvement.
|
781f6ec
to
8367e6d
Compare
8367e6d
to
d41d618
Compare
Do we even need to build |
The question is what happens with validations. Do we want to maintain them in two different places (Tracepoint model and trace.rb)? |
Tracepoint model doesn't need validations because nothing is written using that model. |
Tracepoint.import! calls model validations internally, like we discussed above. Try to upload data without timestamp and see what happens. |
Don't insert data without timestamps.
|
My goal was to replace the activerecord-import gem by a built in equivalent method. Since the validations are not automatically executed anymore, I added the call to the validate method. Rubocop is not clever enough to figure out that we're validating the model contents earlier on, so we need an additional annotation. I really don't have an issue with that. Now we could of course further change the implementation and get rid of the model instances. However, that's a second step, and not needed to replace activerecord-import. That's not to say that this isn't a valid discussion to have, it just doesn't fit well here. |
This PR wasn't merged because
and I'm saying that we shouldn't worry here about model validations and what Rubocop thinks about them. |
This comment still refers to the previous version where the whole file was added to .rubocop.yml. @tomhughes hasn’t commented on the inline annotation variant yet, and I would suggest to wait for feedback before continuing. Like I said, I don’t really have an issue with this annotation. Rubocop is reporting a false positive here and we mark it as such. There's no need to come up with workarounds simply to please the tool. |
Any use of |
A few years back, I've introduced both the activerecord-import gem and At least today, we have exactly one location where |
d41d618
to
6a22d04
Compare
6a22d04
to
7f64307
Compare
This PR removes the activerecord-import dependency and changes the tracepoint import to use
import_all!
instead.I hope I didn't miss anything here. In particular
Tracepoint.insert_all!(tracepoints.map(&:attributes))
would need a review if that's the proper way to import Tracepoint instances.Fixes #4994