Skip to content

Commit

Permalink
Extras field of records should not be None/NULL
Browse files Browse the repository at this point in the history
  • Loading branch information
bennybp committed Oct 30, 2024
1 parent 1e9bab8 commit 1b2dcb9
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""record extras not nullable
Revision ID: 03c96181c90f
Revises: 73b4838a6839
Create Date: 2024-10-30 11:07:37.641631
"""

import sqlalchemy as sa
from alembic import op
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision = "03c96181c90f"
down_revision = "73b4838a6839"
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.execute("""UPDATE base_record SET extras = '{}' WHERE extras IS NULL""")
op.alter_column("base_record", "extras", existing_type=postgresql.JSONB(astext_type=sa.Text()), nullable=False)
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###

# No need to set extras to null - empty dict is still just fine

op.alter_column("base_record", "extras", existing_type=postgresql.JSONB(astext_type=sa.Text()), nullable=True)
# ### end Alembic commands ###
2 changes: 1 addition & 1 deletion qcfractal/qcfractal/components/record_db_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ class BaseRecordORM(BaseORM):
id = Column(Integer, primary_key=True)

# Extra fields
extras = Column(JSONB)
extras = Column(JSONB, nullable=False, default=dict)

# Compute status
# (Denormalized from compute history table for faster lookup during manager claiming/returning)
Expand Down
9 changes: 8 additions & 1 deletion qcportal/qcportal/record_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ class Config:
is_service: bool

properties: Optional[Dict[str, Any]]
extras: Optional[Dict[str, Any]]
extras: Dict[str, Any] = Field({})

status: RecordStatusEnum
manager_name: Optional[str]
Expand Down Expand Up @@ -410,6 +410,13 @@ def __init__(self, client=None, **kwargs):

assert self._client is client, "Client not set in base record class?"

@validator("extras", pre=True)
def _validate_extras(cls, v):
# For backwards compatibility. Older servers may have 'None' as the extras
if v is None:
return {}
return v

def __init_subclass__(cls):
"""
Register derived classes for later use
Expand Down

0 comments on commit 1b2dcb9

Please sign in to comment.