Skip to content

add sopn name fields (part 1)#2639

Merged
chris48s merged 7 commits intomasterfrom
sopn-name1-20260108
Feb 11, 2026
Merged

add sopn name fields (part 1)#2639
chris48s merged 7 commits intomasterfrom
sopn-name1-20260108

Conversation

@chris48s
Copy link
Copy Markdown
Member

@chris48s chris48s commented Jan 8, 2026

The scope of this PR is just to do the behind the scenes bits.
So in this PR I have:

  • added DB fields to store sopn names on the membership
  • added thos fields to the admin/API/CSV outputs
  • populated the fields (as best we can) when we bulk add from SOPN
  • added/updated tests for that functionality

This is a chunk of work that is worth reviewing and deploying, but it is not 100% of what we want to do here.

The second bit of work here will be to allow the user to modify these fields through the frontend and provide some way to discover profiles which are missing this data

I'll do those in a follow up PR (or maybe 2 follow up PRs)

@chris48s chris48s marked this pull request as draft January 8, 2026 12:51
@chris48s chris48s force-pushed the sopn-name1-20260108 branch from 24e8667 to 6af70c9 Compare January 12, 2026 15:24
@chris48s chris48s changed the title add sopn name field add sopn name fields Jan 12, 2026
@chris48s chris48s mentioned this pull request Feb 3, 2026
@chris48s

This comment was marked as outdated.

@chris48s chris48s force-pushed the sopn-name1-20260108 branch from 49827a3 to f1e559c Compare February 4, 2026 15:13
Comment on lines +87 to +88
"sopn_last_name": candidacy.get("sopn_last_name", ""),
"sopn_first_names": candidacy.get("sopn_first_names", ""),
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the biggest question I have on this PR.
I was a bit unsure about using .get("key", "") vs ["key"] in this PR.
I decided to use .get("key", "") here because if we have parsed any SOPN before this is deployed then we're not going to have those keys and we'll throw a KeyError
but then later on in the flow, I've switched to ["key"] but really we have the same issue. If we created a RawPeople object before the deploy, then the code we run after will throw a KeyError.
I wonder if it would make sense to either:

  • Write a data migration to go through any existing parsed SOPN data and add "sopn_last_name": "", "sopn_first_names": "" to every candidate. Then we can just always assume those keys exist
  • Write a data migration to just nuke any parsed SOPN data that exists at the point we deploy on the basis we can re-parse the PDFs. Again, then we can just always assume those keys exist

Thoughts or guidance on this would would be really useful

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I expect the right thing to do here is to model the JSON using some sort of data class (native or Pydantic, etc) and validate against that at run time.

We're not going to do that right now though, are we?

I forget, do we delete the raw people objects after we've added the data in the bulk adding forms? In that case, there aren't going to be many at all outside of a major electon. I think I'm ok with deleting them.

If we never delete any of them, then I reckon the migration is a better idea than having to re-parse everything.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah good thoughts. We seem to keep the AWSTextractParsedSOPN objects around forever, so I guess it makes sense to tolerate the key being missing there. We clear up the RawPeople object after the bulk add process. I had a look at how many RawPeople objects there are in the prod database right now. There's just shy of 100 in there. The most recent was created in June 2025. I suspect they're mostly ones that should have been cleared up but never were. I think that means that just deleting any existing RawPeople objects is the way to go. I'll proceed with that.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread ynr/apps/bulk_adding/templates/bulk_add/sopns/quick_add_form.html
Comment thread ynr/apps/people/admin.py
Comment on lines +64 to +73
@admin.display(description="Membership object")
def admin_link(self, obj):
if not obj.pk:
return "-"
url = reverse(
"admin:popolo_membership_change",
args=[obj.pk],
)
return format_html('<a href="{}">Open</a>', url)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change isn't really strictly related to this PR, but I did find myself wanting it while I was working on this, so I've quickly pushed it onto this branch.

Comment thread ynr/apps/sopn_parsing/helpers/parse_tables.py
Comment thread ynr/apps/sopn_parsing/tests/test_parse_tables.py
@chris48s chris48s requested a review from symroe February 5, 2026 09:13
@chris48s chris48s marked this pull request as ready for review February 5, 2026 09:13
@chris48s chris48s changed the title add sopn name fields add sopn name fields (part 1) Feb 5, 2026
Comment thread ynr/apps/popolo/models.py Outdated
Comment thread ynr/apps/sopn_parsing/helpers/parse_tables.py
Comment thread ynr/apps/sopn_parsing/helpers/parse_tables.py Outdated
@chris48s
Copy link
Copy Markdown
Member Author

chris48s commented Feb 9, 2026

build failures are due to GitHub outage

@chris48s chris48s force-pushed the sopn-name1-20260108 branch from 723fb0e to cc6ae6f Compare February 11, 2026 09:36
@chris48s chris48s merged commit 7e1a28d into master Feb 11, 2026
6 checks passed
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

Successfully merging this pull request may close these issues.

2 participants