ODM2 / ODM2PythonAPI

A set of Python functions that provides data read/write access to an ODM2 database by leveraging SQLAlchemy.
http://odm2.github.io/ODM2PythonAPI/
BSD 3-Clause "New" or "Revised" License
4 stars 13 forks source link

createTimeSeriesResult fails #4

Open Castronova opened 9 years ago

Castronova commented 9 years ago

The following exception is raised when inserting a timeSeriesResult record into a sqlite database: FlushError: Instance <TimeSeriesResults at 0x108ddecd0> has a NULL identity key. The snippet of code below will duplicate this error.

# create a result record
result = models.Results
result.ResultUUID = uuid.uuid4()
result.FeatureActionID = featureaction.FeatureActionID
result.ResultTypeCV = 'time series'
result.VariableID = variable.VariableID
result.UnitsID = unit.UnitsID
result.ProcessingLevelID = processinglevel.ProcessingLevelID
result.ValueCount = len(dates)
result.SampledMediumCV = 'unknown'

# create time series result
# FlushError: Instance <TimeSeriesResults at 0x1174b5fd0> has a NULL identity key.
timeseriesresult = self.write.createTimeSeriesResult(result=result, aggregationstatistic='unknown',
                                                                         timespacing=timestepvalue,
                                                                         timespacing_unitid=timestepunit.UnitsID)
sreeder commented 9 years ago

Note: This error is occurring for multiple database types. @Castronova did you write code to work around this issue? If, so could you post that snippet as well?

Castronova commented 8 years ago

It looks like this error is because the result object does not have a ResultID specified, but ResultUUID instead...user error. I suggest that the createTimeSeriesResults function is modified to accept an integer for ResultID rather than the Result object. This would make it consistent with other api functions, e.g. createSamplingFeature, createAffiliation, createAction, createResult, etc

Might also want to added some assertions to the createService to catch these errors and provide more useful error messages.