Skip to content

Implement PlexosDB.update_property #179

Description

@SebastianManriqueM

Summary

PlexosDB.update_property() is a documented public method but currently always raises NotImplementedError in plexosdb/db.py. This blocks updating existing scenario-bound properties such as Line Wheeling Charge and Wheeling Charge Back; consumers must currently delete and recreate records.

Reproduction

from plexosdb import ClassEnum, PlexosDB

database = PlexosDB.from_xml("model.xml")
database.update_property(
    "line_a",
    "Wheeling Charge",
    10.0,
    object_class=ClassEnum.Line,
    scenario="default",
)

Expected: update the matching existing t_data.value record.

Actual: NotImplementedError at plexosdb/db.py:update_property.

Implementation Plan

  1. Preserve the existing public signature and add complete NumPy-style documentation consistent with get_object_properties() and update_object(), including selection semantics and raised errors.
  2. Resolve the effective collection and parent class using the same default-resolution behavior used by property readers (get_default_collection / ClassEnum.System where applicable). Validate the requested property with the existing property-ID resolution helpers.
  3. Resolve the target object and membership context with existing public/internal project helpers, then obtain matching data_id values through get_object_data_ids() (or the equivalent existing query path), honoring all existing selectors: object_class, object_name, property_name, scenario, band, collection, and parent_class.
  4. Require exactly one matching data record. Raise the package’s established not-found/ambiguity error rather than silently updating several bands, scenarios, or relationship properties.
  5. Follow the style of update_object() for the write: parameterized SQL only, updating Schema.Data / t_data with SET value = ? WHERE data_id = ?, execute through the database manager, and assert/raise consistently on a failed execution. Do not alter metadata such as date range, text, datafile, variable, or timeslice tags.
  6. Implement update_properties() separately or defer it explicitly; it should not be coupled to this single-record implementation unless its transactional input contract is designed and tested.

Test Plan

Add focused pytest coverage in tests/test_plexosdb_list_update_methods.py (or the project’s closest property-update test module):

  • Update a default System-Generator property and verify its value through get_object_properties().
  • Update a System-Line Wheeling Charge and Wheeling Charge Back under the default scenario, then verify both scenario-bound records changed and no duplicate data rows were created.
  • Verify selectors isolate the target scenario and band when otherwise identical property rows exist.
  • Verify a relationship property respects explicit collection and parent_class.
  • Verify missing object/property/data selection produces the project-standard exception and does not mutate another record.
  • Verify the SQL values are bound parameters by exercising names/values requiring normal SQLite parameter handling.

Context

Observed with plexosdb 1.5.0 while generating PLEXOS 10 XML variants. The existing implementation at db.py lines 4339-4353 is a stub, while nearby update_object() demonstrates the repository’s parameterized UPDATE style.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions