codeforcroatia / imamopravoznati

Provide a Freedom of Information request system for your jurisdiction
http://alaveteli.org
Other
3 stars 1 forks source link

Multiple public bodies (2) found with url_name 'internal_admin_authority' #76

Closed schlos closed 4 years ago

schlos commented 5 years ago

Actual behavior

[ERROR] [imamopravoznati.org] public_body#list (RuntimeError) "Multiple public bodies (2) found with urlname 'internal...

A RuntimeError occurred in public_body#list:

  Multiple public bodies (2) found with url_name 'internal_admin_authority'
  app/models/public_body.rb:390:in `internal_admin_body'

-------------------------------
Request:
-------------------------------

  * URL        : http://www.imamopravoznati.org/en/body/list/o
  * HTTP Method: GET
  * IP address :  
  * Parameters : {"controller"=>"public_body", "action"=>"list", "tag"=>"o", "locale"=>"en"}
  * Timestamp  : 2019-09-10 10:10:24 +0200
  * Server : imamopravoznati
  * Rails root : /var/www/imamopravoznati.org/alaveteli
  * Process: 19790

-------------------------------
Backtrace:
-------------------------------

  app/models/public_body.rb:390:in `internal_admin_body'
  app/controllers/public_body_controller.rb:131:in `list'
  app/controllers/application_controller.rb:120:in `record_memory'
  lib/strip_empty_sessions.rb:13:in `call'

Steps to reproduce

Go to http://www.imamopravoznati.org/en/body/list/o

Expected behavior

Should work

garethrees commented 5 years ago

Hmm strange this came up at https://groups.google.com/forum/#!topic/alaveteli-dev/YoOrH_qVDxc. Plz to comment there if you find a fix before us!

schlos commented 4 years ago

Issue has been resolved with solution shared by Alaveteli Dev team on AlaveteliCon 2019:

It's same issue as Elenor's issue: https://groups.google.com/forum/m/#!topic/alaveteli-dev/YoOrH_qVDxc

Reproduce with: AlaveteliLocalization.with_locale('sv') { PublicBody.where(url_name: 'internal_admin_authority') } where sv is your site locale.

So this appears to be a issue with Rails <=4.2 which is why we couldn't reproduce on WDTK with Rails 5

Check your Internal Authority body (run in Rails console): PublicBody::Translation.where(url_name: 'internal_admin_authority').where.not(locale: AlaveteliLocalization.default_locale)

Possible quick fix (run in Rails console): PublicBody::Translation.where(url_name: 'internal_admin_authority').where.not(locale: AlaveteliLocalization.default_locale).destroy_all << be careful about running this!!

schlos commented 4 years ago

After migration same issue was reproduced:

A RuntimeError occurred in public_body#list:

Multiple public bodies (2) found with url_name 'internal_admin_authority' app/models/public_body.rb:390:in `internal_admin_body'

Database:

SELECT * FROM public_body_translations WHERE url_name = 'internal_admin_authority';

  id   | public_body_id | locale | first_letter |         request_email          | publication_scheme | notes | short_name |           name           |         url_name         |         created_at         |         updated_at         | disclosure_log 
-------+----------------+--------+--------------+--------------------------------+--------------------+-------+------------+--------------------------+--------------------------+----------------------------+----------------------------+----------------
     6 |              1 | hr     | I            | REDACTED |                    |       |            | Internal admin authority | internal_admin_authority | 2015-02-21 12:46:38.527393 | 2015-02-21 14:18:53.037204 | 
 34547 |              1 | en     | I            | REDACTED |                    |       |            | Internal admin authority | internal_admin_authority | 2019-10-13 06:23:40.211418 | 2019-10-13 06:23:40.211418 | 
(2 rows)
schlos commented 4 years ago

After running in rails console:

PublicBody::Translation.where(url_name: 'internal_admin_authority').where.not(locale: AlaveteliLocalization.default_locale).destroy_all

Result in db:

 id | public_body_id | locale | first_letter |         request_email          | publication_scheme | notes | short_name |           name           |         url_name         |         created_at         |         updated_at         | disclosure_log 
----+----------------+--------+--------------+--------------------------------+--------------------+-------+------------+--------------------------+--------------------------+----------------------------+----------------------------+----------------
  6 |              1 | hr     | I            | REDACTED |                    |       |            | Internal admin authority | internal_admin_authority | 2015-02-21 12:46:38.527393 | 2015-02-21 14:18:53.037204 | 
(1 row)