Skip to content

Cannot create Action or Actionby #67

@Castronova

Description

@Castronova

The ActionBy class is a required input to the createAction function and ActionID is required to create an instance of the ActionBy class. Unfortunately, I cannot get an ActionID without inserting an action into the database. Is this a mistake, or am I missing something? Are there any examples of how this is supposed to work?

models.py

class ActionBy(Base):
    BridgeID = Column('bridgeid', Integer, primary_key=True, nullable=False)
    ActionID = Column('actionid', Integer, ForeignKey(Actions.ActionID), nullable=False)
    AffiliationID = Column('affiliationid', ForeignKey(Affiliations.AffiliationID), nullable=False)
    IsActionLead = Column('isactionlead', Boolean, nullable=False)
    RoleDescription = Column('roledescription', String(500))
    ActionObj = relationship(Actions)
    AffiliationObj = relationship(Affiliations)

class Actions(Base):
    ActionID = Column('actionid', Integer, primary_key=True, nullable=False)
    ActionTypeCV = Column('actiontypecv', ForeignKey(CVActionType.Name), nullable=False, index=True)
    MethodID = Column('methodid', ForeignKey(Methods.MethodID), nullable=False)
    BeginDateTime = Column('begindatetime', DateTime, nullable=False)
    BeginDateTimeUTCOffset = Column('begindatetimeutcoffset', Integer, nullable=False)
    EndDateTime = Column('enddatetime', DateTime)
    EndDateTimeUTCOffset = Column('enddatetimeutcoffset', Integer)
    ActionDescription = Column('actiondescription', String(500))
    ActionFileLink = Column('actionfilelink', String(255))
    MethodObj = relationship(Methods)

    def __repr__(self):
        return "<Actions('%s', '%s', '%s', '%s')>" % (
            self.ActionID, self.ActionTypeCV, self.BeginDateTime, self.ActionDescription)

createService.py

def createAction(self, action, actionby):
        self._session.add(action)
        self._session.add(actionby)
        self._session.commit()

Below is my attempt to insert an Action:

# create an instance of ActionBy (without ActionID, since it is unknown at this time)
ab = models.ActionBy()
ab.AffiliationID = affiliation[0].AffiliationID
ab.IsActionLead = True

# create an instance of Actions.        
a = models.Actions()
a.ActionTypeCV = 'Simulation'
a.MethodID = method.MethodID
a.BeginDateTime = datetime.datetime.now()
a.BeginDateTimeUTCOffset = int((datetime.datetime.now() - datetime.datetime.utcnow()).total_seconds()/3600)

# create the Action (and ActionBy)
self.write.createAction(a, ab)
 actions = self.read.getActions(type=a.ActionTypeCV)

Error
IntegrityError: (sqlite3.IntegrityError) NOT NULL constraint failed: ActionBy.ActionID

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions