Worldcubeassociation.org: Past competition index crashes when registration close is not set

Created on 28 Jun 2019  路  3Comments  路  Source: thewca/worldcubeassociation.org

Describe the bug
This page is crashed now: https://www.worldcubeassociation.org/competitions/AnkaraSummer2018.
The competition doesn't have registration_open and registration_close. But the on_the_spot_registration is enabled and on_the_spot_entry_fee_lowest_denomination is above zero. So it crashes.

To Reproduce
Go to https://www.worldcubeassociation.org/competitions/AnkaraSummer2018

Expected behavior
Page should not be creashed

Additional context
Here's the related log:

I, [2019-06-28T02:36:16.562336 #6000]  INFO -- : [facc6d06-e0c1-4591-bee7-78bd753cef39] Completed 500 Internal Server Error in 81ms (ActiveRecord: 31.8ms)
I, [2019-06-28T02:36:16.562495 #6000]  INFO -- : [facc6d06-e0c1-4591-bee7-78bd753cef39] [User Id] Request was made by user id: 9
F, [2019-06-28T02:36:16.563963 #6000] FATAL -- : [facc6d06-e0c1-4591-bee7-78bd753cef39]
F, [2019-06-28T02:36:16.564016 #6000] FATAL -- : [facc6d06-e0c1-4591-bee7-78bd753cef39] ActionView::Template::Error (undefined method `in_time_zone' for nil:NilClass):
F, [2019-06-28T02:36:16.564267 #6000] FATAL -- : [facc6d06-e0c1-4591-bee7-78bd753cef39]     71: <% if @competition.on_the_spot_registration.nil? %>
[facc6d06-e0c1-4591-bee7-78bd753cef39]     72: <% elsif @competition.on_the_spot_registration? %>
[facc6d06-e0c1-4591-bee7-78bd753cef39]     73:   <% if @competition.on_the_spot_entry_fee_lowest_denomination? %>
[facc6d06-e0c1-4591-bee7-78bd753cef39]     74:     <%= t('competitions.competition_info.on_the_spot_registration_html', on_the_spot_base_entry_fee: format_money(@competition.on_the_spot_base_entry_fee), end_of_registration: wca_local_time(@competition.registration_close)) %>
[facc6d06-e0c1-4591-bee7-78bd753cef39]     75:     <br>
[facc6d06-e0c1-4591-bee7-78bd753cef39]     76:   <% else %>
[facc6d06-e0c1-4591-bee7-78bd753cef39]     77:     <%= t('competitions.competition_info.on_the_spot_registration_free') %>
F, [2019-06-28T02:36:16.564306 #6000] FATAL -- : [facc6d06-e0c1-4591-bee7-78bd753cef39]
F, [2019-06-28T02:36:16.564339 #6000] FATAL -- : [facc6d06-e0c1-4591-bee7-78bd753cef39] app/helpers/application_helper.rb:84:in `wca_local_time'
[facc6d06-e0c1-4591-bee7-78bd753cef39] app/views/competitions/_registration_requirements.html.erb:74:in `_app_views_competitions__registration_requirements_html_erb__1559039616541743090_88288260'
[facc6d06-e0c1-4591-bee7-78bd753cef39] app/views/competitions/_competition_info.html.erb:133:in `_app_views_competitions__competition_info_html_erb__3580336813344321049_87702060'
[facc6d06-e0c1-4591-bee7-78bd753cef39] app/views/competitions/_results_nav.html.erb:2:in `block in _app_views_competitions__results_nav_html_erb__3186922944650161649_87675540'
[facc6d06-e0c1-4591-bee7-78bd753cef39] app/views/competitions/_results_nav.html.erb:1:in `_app_views_competitions__results_nav_html_erb__3186922944650161649_87675540'
[facc6d06-e0c1-4591-bee7-78bd753cef39] app/views/competitions/show.html.erb:19:in `block in _app_views_competitions_show_html_erb___2497902672611384778_85503320'
[facc6d06-e0c1-4591-bee7-78bd753cef39] app/views/competitions/_nav.html.erb:236:in `_app_views_competitions__nav_html_erb__4101342721595342269_85772080'
[facc6d06-e0c1-4591-bee7-78bd753cef39] app/views/competitions/show.html.erb:3:in `_app_views_competitions_show_html_erb___2497902672611384778_85503320'
[facc6d06-e0c1-4591-bee7-78bd753cef39] lib/middlewares/warden_user_logger.rb:13:in `call'
[facc6d06-e0c1-4591-bee7-78bd753cef39] lib/middlewares/fix_accept_header.rb:14:in `call'
bug

Most helpful comment

It looks like this is the only competition in this state:

mysql> SELECT id FROM Competitions WHERE registration_close is NULL AND on_the_spot_registration=1 AND on_the_spot_entry_fee_lowest_denomination > 0;                                                                                 +------------------+
| id               |
+------------------+
| AnkaraSummer2018 |
+------------------+
1 row in set (0.01 sec)

As far as our competition model is concerned, it's treating this competition as "valid":

~/worldcubeassociation.org/WcaOnRails @production> RACK_ENV=production bin/rails c
irb(main):005:0> Competition.find("AnkaraSummer2018").valid?
=> true

I think we should either update our validations to not allow this, or change our view code to handle the case where registration_close is not set. @AlbertoPdRF, can you think through exactly how this should work?

Would the best way to fix this bug be to manually edit the row(s) on the database so the corresponding pages don't crash?

I think we can avoid going to the database and instead fix this by clicking around on https://www.worldcubeassociation.org/competitions/AnkaraSummer2018/edit/admin.

All 3 comments

Are there any more competitions with this issue? Would the best way to fix this bug be to manually edit the row(s) on the database so the corresponding pages don't crash?

It looks like this is the only competition in this state:

mysql> SELECT id FROM Competitions WHERE registration_close is NULL AND on_the_spot_registration=1 AND on_the_spot_entry_fee_lowest_denomination > 0;                                                                                 +------------------+
| id               |
+------------------+
| AnkaraSummer2018 |
+------------------+
1 row in set (0.01 sec)

As far as our competition model is concerned, it's treating this competition as "valid":

~/worldcubeassociation.org/WcaOnRails @production> RACK_ENV=production bin/rails c
irb(main):005:0> Competition.find("AnkaraSummer2018").valid?
=> true

I think we should either update our validations to not allow this, or change our view code to handle the case where registration_close is not set. @AlbertoPdRF, can you think through exactly how this should work?

Would the best way to fix this bug be to manually edit the row(s) on the database so the corresponding pages don't crash?

I think we can avoid going to the database and instead fix this by clicking around on https://www.worldcubeassociation.org/competitions/AnkaraSummer2018/edit/admin.

Should we start to always require registration_open and registration_close, or do we have a good reason for not doing so? Also, I feel like fixing the view is the "easy" way to go, but not the best one.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jfly picture jfly  路  7Comments

Nanush7 picture Nanush7  路  3Comments

Jambrose777 picture Jambrose777  路  3Comments

AlexKatyukov picture AlexKatyukov  路  3Comments

jfly picture jfly  路  4Comments