-
Notifications
You must be signed in to change notification settings - Fork 438
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
Bugfix/backend file #5183
Bugfix/backend file #5183
Conversation
src/api/app/models/package.rb
Outdated
@@ -1457,7 +1457,7 @@ def last_build_reason(repo, arch, package_name = nil) | |||
arch: arch | |||
) | |||
|
|||
data = Xmlhash.parse(xml_data.to_s) | |||
data = Xmlhash.parse(xml_data.to_s.to_s) |
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.
I think this is the ultimate sign that to_s just has the wrong name
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.
Definetly:+1:
2e1ca94
to
5a86d9f
Compare
bb8088e
to
0ab9c41
Compare
@@ -55,8 +55,8 @@ def file(query = {}) | |||
nil | |||
end | |||
|
|||
# Converts file into a String if it's valid | |||
def to_s(query = {}) | |||
# Converts file into a String if it's valid and nil if it's not |
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.
Is this comment really needed? The method is pretty clear... 🤔
src/api/lib/backend/file.rb
Outdated
# Converts file into a String if it's valid | ||
def to_s(query = {}) | ||
# Converts file into a String if it's valid and nil if it's not | ||
def content(query = {}) | ||
file(query) | ||
@file && valid? ? ::File.open(@file.path).read : nil |
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.
There should be a Rubocop cop to avoid using nil
like this... :sob
d75c573
to
a35cca0
Compare
Please don't merge this until #5140 is in - or you break the existing engine (as it's using .to_s) |
a35cca0
to
b9f3100
Compare
The BuildReasonFile model was abstracting the _reason file that is stored in the backend. Though the only place where this method was used we parsed the raw xml and created another object (PackageBuildReason) out of it. Because of that it makes sense to drop this model and use a Backend::Api call like we already do elsewhere. In addition this solves an issue caused by BuildReasonFile#to_s returning nil when the file isn't available or invalid. Kudos for the idea goes to @DavidKang
6fdd78d
to
8c02dd7
Compare
Calling it to_s was a bit misleading since this method would return nil when the requested file does not exist or is invalid.
8c02dd7
to
62daff3
Compare
@DavidKang @coolo I had to update a couple of places that were using the backend file class. Would you mind to have a second look? |
@@ -145,14 +145,14 @@ def self.restore(project_name, backend_opts = {}) | |||
project = Project.new(name: project_name) | |||
|
|||
Project.transaction do | |||
project.update_from_xml!(Xmlhash.parse(project.meta.to_s)) | |||
project.update_from_xml!(Xmlhash.parse(project.meta.content)) |
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.
is there any value in having meta not returning content right away? (just curious as you it .meta.content appears quite often in your PR)
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.
We would have to look closer into this. But you are right it seems that we only use the content right now.
The other thing is that there is a similar method called config and might be some others. I would keep them in sync.
One more test suite problem hidden by cassettes:
|
No description provided.