Skip to content

Dates array should be sorted chronologically #9

Description

@chris48s

Problem: At the moment, the dates[] array is just sorted in the order we add the ballots in.

This means that we can do something like

MULTIPLE_BALLOTS_WITH_VOTING_SYSTEM_AND_POLLING_STATION = (
RootBuilder()
.with_multiple_ballots(
[
MAYOR_BALLOT.with_candidates(candidates.all_candidates).build(),
GLA_BALLOT.with_candidates(candidates.all_candidates).build(),
]
)
.with_polling_station(WITHOUT_MAP_POLLING_STATION.build())
.with_electoral_services(electoral_services.stroud_electoral_services)
)

In this example, the GLA_BALLOT has a date before the MAYOR_BALLOT

GLA_BALLOT = (
StockLocalBallotBuilder()
.with_ballot_title("London Assembly elections")
.with_post_name("London Assembly")
.with_election_name("London Assembly elections")
.with_ballot_paper_id("gla.a.2024-05-02")
.with_election_id("gla.a.2024-05-02")
)

MAYOR_BALLOT = (
StockLocalBallotBuilder()
.with_ballot_title("Mayor of London")
.with_post_name("Mayor of London")
.with_election_name("Mayor of London")
.with_ballot_paper_id("mayor.london.2024-11-02")
.with_election_id("mayor.london.2024-11-02")
.with_voting_system("FPTP")
.with_candidates(candidates.all_candidates)
)

but because we add it second, it comes after it in the dates array. This is unexpected by client apps, the set_date_baseline() function, etc.

Solution: We should ensure that whatever order we add ballots in (either using .with_multiple_ballots() or chained calls to with_ballot() the ballots come out in chronological order in the final response.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions