Skip to content

DB Write and read give different results #50

@gymzombie

Description

@gymzombie

Not sure if this is a bug or intended functionality.

I create a model and write it to the database. (v1)
I decide I want to change the parameters of that model and adjust the values, then write it to the database. (v2)
I load the model from the database, and the output shows the model for v1.

Sample code to reproduce:

# Create an initial model
model = FairModel('System 1, Risk A')
model.bulk_import_data({
    'Loss Event Frequency': {'mean':.3, 'stdev':.1},
    'Loss Magnitude': {'constant': 5_000_000}
})
model.calculate_all()

# Create a database file and store that model
db = FairDatabase('pyfair.sqlite3')
db.store(model)

# Create a new version of that model
model = FairModel('System 1, Risk 1')
model.bulk_import_data({
    'Threat Event Frequency': {'low':.3, 'mode':.6, 'high':.9},
    'Vulnerability':{'constant':.5},
    'Loss Magnitude': {'constant': 5_000_000}
})
model.calculate_all()

# Write the updated version of that model to the database
db.store(model)

# Load the model
reconstituted_model = db.load('System 1, Risk A')
reconstituted_model.calculate_all()

fsr = FairSimpleReport([reconstituted_model])
fsr.to_html('output.html')

This also might just be a style/documentation issue? Since we read and write based on the model name, but the database reads and writes based on the UID, it's just unexpected behavior for a new user.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    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