FEATURE: Can edit category/host relationships for embedding#10
Open
ShashankFC wants to merge 1 commit into
Open
FEATURE: Can edit category/host relationships for embedding#10ShashankFC wants to merge 1 commit into
ShashankFC wants to merge 1 commit into
Conversation
Comment on lines
+9
to
+11
| category_id = execute("SELECT c.id FROM categories AS c | ||
| INNER JOIN site_settings AS s ON s.value = c.name | ||
| WHERE s.name = 'embed_category'")[0]['id'].to_i |
There was a problem hiding this comment.
This query will crash if no matching category is found, as it tries to access [0]['id'] on a potentially empty result set. Needs nil checking.
result = execute("SELECT c.id FROM categories AS c...")
category_id = result.first ? result.first['id'].to_i : 0
Suggested change
| category_id = execute("SELECT c.id FROM categories AS c | |
| INNER JOIN site_settings AS s ON s.value = c.name | |
| WHERE s.name = 'embed_category'")[0]['id'].to_i | |
| result = execute("SELECT c.id FROM categories AS c | |
| INNER JOIN site_settings AS s ON s.value = c.name | |
| WHERE s.name = 'embed_category'") | |
| category_id = result.first ? result.first['id'].to_i : 0 |
Spotted by Graphite Agent
Is this helpful? React 👍 or 👎 to let us know.
Comment on lines
+5
to
+8
| before_validation do | ||
| self.host.sub!(/^https?:\/\//, '') | ||
| self.host.sub!(/\/.*$/, '') | ||
| end |
There was a problem hiding this comment.
Calling sub! on self.host will raise NoMethodError if host is nil. Needs nil check before mutation.
before_validation do
if self.host.present?
self.host.sub!(/^https?:\/\//, '')
self.host.sub!(/\/.*$/, '')
end
end
Suggested change
| before_validation do | |
| self.host.sub!(/^https?:\/\//, '') | |
| self.host.sub!(/\/.*$/, '') | |
| end | |
| before_validation do | |
| if self.host.present? | |
| self.host.sub!(/^https?:\/\//, '') | |
| self.host.sub!(/\/.*$/, '') | |
| end | |
| end | |
Spotted by Graphite Agent
Is this helpful? React 👍 or 👎 to let us know.
Comment on lines
+10
to
+11
| host = EmbeddableHost.where(id: params[:id]).first | ||
| save_host(host) |
There was a problem hiding this comment.
If no host is found with the given ID, host will be nil and calling save_host(nil) will cause NoMethodError when accessing nil properties.
def update
host = EmbeddableHost.where(id: params[:id]).first
return render_json_error('Host not found', status: 404) unless host
save_host(host)
end
Suggested change
| host = EmbeddableHost.where(id: params[:id]).first | |
| save_host(host) | |
| host = EmbeddableHost.where(id: params[:id]).first | |
| return render_json_error('Host not found', status: 404) unless host | |
| save_host(host) | |
Spotted by Graphite Agent
Is this helpful? React 👍 or 👎 to let us know.
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.
Test 10
Replicated from ai-code-review-evaluation/discourse-graphite#10