DemocracyClub / yournextrepresentative

👥 A website for crowd-sourcing structured election candidate data
https://candidates.democracyclub.org.uk
GNU Affero General Public License v3.0
21 stars 27 forks source link

Import from live site doesn't store "elected" field #1502

Open michaeljcollinsuk opened 3 years ago

michaeljcollinsuk commented 3 years ago

Issue and Steps to Reproduce

When using the import_from_live_site management command to populate a local DB, fields such as elected are not stored when creating people and their candidacies. I believe the reason for this is because on the Serializer that is used, the field is marked as a ReadOnlyField. So that when the serialised is saved as part of the import process, these values are ignored.

As the API is read-only anyway (although this is my assumption - is this correct) I don't know if it is necessary to mark these fields (and others) as read only? That would then ensure that all values are imported from the live DB.

Alternatively, we could leave the serialisers as they are, and create specific serialisers for the importers to ensure all data is stored.

symroe commented 3 years ago

As the API is read-only anyway (although this is my assumption - is this correct) I don't know if it is necessary to mark these fields (and others) as read only? That would then ensure that all values are imported from the live DB.

I'd like to test the assumption that it's the read only flag that's causing this - it seems plausible, but then some data does get saved!

The reason we need the read only stuff is because we generate the documentation from the code. If we don't mark them as read only this page starts listing POST, PUT etc

symroe commented 3 years ago

Related, but with no issue I don't think, person IDs don't get assigned when pulling from the live site. Each Person gets an ID of course, but they're not the same ID as the remove site. I think we should try to make the importer actually mirror the site, including IDs (seeing as we do use those IDs for quite a lot of things!)