When deleting an election, the following notice appears:

Notice: Undefined index: [num] in election_post_entity_load() (line 404 of .../modules/election/election_post/election_post.module).

Comments

Liam Morland created an issue. See original summary.

liam morland’s picture

Assigned: liam morland » Unassigned
Status: Active » Needs review
StatusFileSize
new608 bytes
pjcdawkins’s picture

Status: Needs review » Postponed (maintainer needs more info)

I'd be reluctant to hide this notice. As posts are deleted when their elections are deleted (through election_post_entity_delete()), it should be impossible that this happens. So the notice reveals another bug, perhaps.

liam morland’s picture

Could be. I just saw the notice when I deleted an election.

liam morland’s picture

I notice that election_post_entity_load() calls election_load_multiple(), which calls entity_load(). Would that not loop back and trigger hook_entity_load() again? That would explain why I get the error message multiple times with the same number as the undefined index every time it happens.

liam morland’s picture

Status: Postponed (maintainer needs more info) » Active

Steps to reproduce:

  1. Create an election.
  2. Create a position in that election.
  3. Delete the election.

An election without any positions does not cause this error.

The undefined index is the election_id of the deleted election.

liam morland’s picture

Title: Undefined index: 5 in election_post_entity_load() » Undefined index: [num] in election_post_entity_load()
pjcdawkins’s picture

Status: Active » Fixed

OK, thanks for the update - committed

liam morland’s picture

I'm a bit concerned that my fix may not be the right thing; I don't understand the code well enough to know. As I suggested in #5, the code could be, in effect, calling itself. That is probably not what should happen. But you know the code better than I do, so I trust you judgement.

pjcdawkins’s picture

I notice that election_post_entity_load() calls election_load_multiple(), which calls entity_load(). Would that not loop back and trigger hook_entity_load() again?

Yes, but that's OK - it would trigger hook_entity_load() for the 'election' entity type, not 'election_post'. The hook has the entity type as the second parameter.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.