WikiEducationFoundation / WikiEduDashboard

Wiki Education Foundation's Wikipedia course dashboard system
https://dashboard.wikiedu.org
MIT License
392 stars 631 forks source link

Updates logic to handle rev_ids that do not have entries in the returned analyzed_revisions #6033

Closed empty-codes closed 1 week ago

empty-codes commented 1 week ago

What this PR does

NoMethodError: undefined method `each' for nil:NilClass

            revisions.each do |revision|
                     ^^^^^
2024-11-08T18:39:34.328Z pid=259956 tid=2qjk WARN: /usr/share/rvm/gems/ruby-3.1.2/gems/wikidata-diff-analyzer-2.0.2/lib/wikidata/diff/api.rb:37:in `block in get_revision_contents'
/usr/share/rvm/gems/ruby-3.1.2/gems/wikidata-diff-analyzer-2.0.2/lib/wikidata/diff/api.rb:33:in `each'
/usr/share/rvm/gems/ruby-3.1.2/gems/wikidata-diff-analyzer-2.0.2/lib/wikidata/diff/api.rb:33:in `get_revision_contents'
/// more trace
[2024-11-09 00:04:39.791 ERROR] WikidataDiffAnalyzer failed: undefined method each' for nil:NilClass

            revisions.each do |revision|
                     ^^^^^
2024-11-08T23:04:50.005Z pid=347281 tid=5yx5 class=UpdateWikidataStatsWorker jid=c35f8b253141fd95981b4eb9 elapsed=348.827 INFO: fail
2024-11-08T23:04:50.005Z pid=347281 tid=5yx5 WARN: {"context":"Job raised exception","job":{"retry":0,"queue":"default","lock":"until_executed","args":[10023],"class":"UpdateWikidataStatsWorker","jid":"c35f8b253141fd95981b4eb9","created_at":1731106694.587861,"lock_timeout":0,"lock_ttl":null,"lock_prefix":"uniquejobs","lock_args":[10023],"lock_digest":"uniquejobs:7d68026e21a02b7f84f2dc4a8bb29dc3","enqueued_at":1731106694.633427}}
2024-11-08T23:04:50.007Z pid=347281 tid=5yx5 WARN: NoMethodError: undefined method each' for nil:NilClass

      deserialized_stat.each do |key, value|
                       ^^^^^
2024-11-08T23:04:50.007Z pid=347281 tid=5yx5 WARN: /home/emptycodes/WikiEduDashboard/app/services/update_wikidata_stats.rb:173:in block in get_stats_from_serialized_stats'
/home/emptycodes/WikiEduDashboard/app/services/update_wikidata_stats.rb:169:in each'
/home/emptycodes/WikiEduDashboard/app/services/update_wikidata_stats.rb:169:in get_stats_from_serialized_stats'
/home/emptycodes/WikiEduDashboard/app/services/update_wikidata_stats.rb:138:in update_wikidata_statistics'
/home/emptycodes/WikiEduDashboard/app/services/update_wikidata_stats.rb:75:in initialize'
// more trace

Screenshots

I tested it on two courses, the buggy course with id 10023, and a random course with id 10022: job worker

course_id 10023: start stop

course_id 10022: another course

So the added logic should not affect / break the wikidata stats update process.

Note: I had Metrics/ClassLength and Metrics/MethodLength lint errors so I initially tried to shorten the code logic, which actually led to more lint errors so I searched slack and you once said to wrap the whole class in the rubocop special comment to disable a rule for the file, and so I did that.