Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Users cannot deprecate entries with sale agents that lack authority records #16

Open
demery opened this issue Feb 11, 2020 · 0 comments

Comments

@demery
Copy link
Member

demery commented Feb 11, 2020

When users attempt to deprecate entries with sale agents who have an observed name but no authority record, an exception is raised:

A NoMethodError occurred in entries#deprecate:

 undefined method `id' for nil:NilClass
 app/models/entry.rb:221:in `block in decrement_counters'
 app/models/entry.rb:220:in `each'
 app/models/entry.rb:220:in `decrement_counters'
 app/controllers/entries_controller.rb:538:in `block in deprecate'
 app/controllers/entries_controller.rb:495:in `deprecate'

The problem occurs here:

https://github.com/upenn-libraries/sdbmss/blob/master/app/models/entry.rb#L219-L224

    if sale
      sale.sale_agents.map(&:agent).uniq.each do |sale_agent|
        Name.decrement_counter(:sale_agents_count, sale_agent.id)
        objects.push(sale_agent)
      end
    end

The problem occurred with SDBM_ 8263, which has sale agents below. Note that the agent with observed_name 'Llewellyn' has a null agent_id.

mysql> select * from sale_agents where sale_id = 8257;
+--------+---------+---------------+----------+------------------+---------------------+---------------------+---------------------+------------------------+
| id     | sale_id | observed_name | agent_id | role             | created_at          | updated_at          | uncertain_in_source | supplied_by_data_entry |
+--------+---------+---------------+----------+------------------+---------------------+---------------------+---------------------+------------------------+
|  12068 |    8257 | NULL          |     7322 | selling_agent    | NULL                | NULL                |                   0 |                      0 |
|  12069 |    8257 | NULL          |    12621 | seller_or_holder | NULL                | NULL                |                   0 |                      0 |
| 160151 |    8257 | Llewellyn     |     NULL | buyer            | 2020-02-03 20:20:44 | 2020-02-03 20:20:44 |                   0 |                      0 |
+--------+---------+---------------+----------+------------------+---------------------+---------------------+---------------------+------------------------+

The problem can be corrected by skipping agents without an agent_id:

    if sale
      sale.sale_agents.map(&:agent).uniq.each do |sale_agent|
        next if sale_agent.blank? # skip if agent_id is null <= Add this line
        Name.decrement_counter(:sale_agents_count, sale_agent.id)
        objects.push(sale_agent)
      end
    end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant