Saving badge title without changing value produces an error


(Wladimir Palant) #1

Steps to reproduce:

  1. Click your avatar in the upper-right corner.
  2. Choose “Preferences.”
  3. Click the icon to edit your title.
  4. If the selection isn’t preset to <none> - change it to <none>, save and reload the page.
  5. Click “Save Changes” without actually changing the selection.

Results:

A message “Sorry, an error has occurred.” shows up. Admin logs show the following error:

ActionController::ParameterMissing (param is missing or the value is empty: user_badge_id)

vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.10/lib/action_controller/metal/strong_parameters.rb:187:in `require'
app/controllers/users_controller.rb:132:in `badge_title'
vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.10/lib/action_controller/metal/implicit_render.rb:4:in `send_action'

If you change the selection before submitting then the error doesn’t occur - even if you change it to <none> again.

I could not reproduce here because I don’t have the necessary badges. However, our Discourse instance is at this revision which is fairly recent.


#2

Im test it, its work ! Without any error


(Wladimir Palant) #3

Interesting. I did look through the list of changes in the past five days but didn’t notice anything that would be relevant here.


#4

Im test in 3 discourse site , dont ahave any error
you rebuild your app and test it again
and your discourse version?


(Wladimir Palant) #5

Actually, I could reproduce this issue on meta - there is no link to Discourse Meta but I can access it nevertheless. Going there and clicking “Save Changes” produces the error message I mentioned.

@Qasem_h: As the steps to reproduce say, you should not change the selection. Just click the button when the page loads, don’t do anything else. As to our Discourse version, it’s mentioned in the first post.


#6

this error when showing you send a empty value


(Wladimir Palant) #7

Sure, that’s what the error message says already :wink:

The point is, this value shouldn’t be empty. If you change selection to <none> then “user_badge_id=undefined” is being sent, same should happen if you don’t touch the selection.


(Wladimir Palant) #8

The problematic request is this one. The problem is, self.get('selectedUserBadgeId') returns undefined if no badge is selected and the user didn’t change the selection. jQuery drops any parameters with undefined as value. On the other hand, after the user changed the selection self.get('selectedUserBadgeId') will return "undefined" (a string). jQuery serializes this one correctly, no issue here.

Interestingly, there is no issue on Discourse Meta even though the code looks pretty much identical.