<commit_before>#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

from oslo_config import cfg
from oslo_log import log as logging
from oslo_serialization import jsonutils
from oslo_versionedobjects import fields

from smaug import db
from smaug import exception
from smaug.i18n import _
from smaug import objects
from smaug.objects import base

CONF = cfg.CONF
LOG = logging.getLogger(__name__)


@base.SmaugObjectRegistry.register
class ScheduledOperation(base.SmaugPersistentObject, base.SmaugObject,
                         base.SmaugObjectDictCompat,
                         base.SmaugComparableObject):
    # Version 1.0: Initial version
    VERSION = '1.0'

    fields = {
        'id': fields.UUIDField(),
        'name': fields.StringField(),
        'description': fields.StringField(),
        'operation_type': fields.StringField(),
        'user_id': fields.StringField(),
        'project_id': fields.StringField(),
        'trigger_id': fields.UUIDField(),
        'operation_definition': fields.DictOfStringsField(),

        'trigger': fields.ObjectField("Trigger")
    }

    INSTANCE_OPTIONAL_JOINED_FIELDS = ['trigger']

    @staticmethod
    def _from_db_object(context, op, db_op, expected_attrs=[]):
        special_fields = set(['operation_definition'] +
                             op.INSTANCE_OPTIONAL_JOINED_FIELDS)

        normal_fields = set(op.fields) - special_fields
        for name in normal_fields:
            op[name] = db_op.get(name)

        op_definition = db_op['operation_definition']
        if op_definition:
            op['operation_definition'] = jsonutils.loads(op_definition)

        if 'trigger' in expected_attrs:
            if db_op.get('trigger', None) is None:
                op.trigger = None
            else:
                if not op.obj_attr_is_set('trigger'):
                    op.trigger = objects.Trigger(context)<commit_msg>Fix Scheduled Operation Creation failed<commit_after>#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

from oslo_config import cfg
from oslo_log import log as logging
from oslo_serialization import jsonutils
from oslo_versionedobjects import fields

from smaug import db
from smaug import exception
from smaug.i18n import _
from smaug import objects
from smaug.objects import base

CONF = cfg.CONF
LOG = logging.getLogger(__name__)


@base.SmaugObjectRegistry.register
class ScheduledOperation(base.SmaugPersistentObject, base.SmaugObject,
                         base.SmaugObjectDictCompat,
                         base.SmaugComparableObject):
    # Version 1.0: Initial version
    VERSION = '1.0'

    fields = {
        'id': fields.UUIDField(),
        'name': fields.StringField(),
        'description': fields.StringField(nullable=True),
        'operation_type': fields.StringField(),
        'user_id': fields.StringField(),
        'project_id': fields.StringField(),
        'trigger_id': fields.UUIDField(),
        'operation_definition': fields.DictOfStringsField(),

        'trigger': fields.ObjectField("Trigger")
    }

    INSTANCE_OPTIONAL_JOINED_FIELDS = ['trigger']

    @staticmethod
    def _from_db_object(context, op, db_op, expected_attrs=[]):
        special_fields = set(['operation_definition'] +
                             op.INSTANCE_OPTIONAL_JOINED_FIELDS)

        normal_fields = set(op.fields) - special_fields
        for name in normal_fields:
            op[name] = db_op.get(name)

        op_definition = db_op['operation_definition']
        if op_definition:
            op['operation_definition'] = jsonutils.loads(op_definition)

        if 'trigger' in expected_attrs:
            if db_op.get('trigger', None) is None:
                op.trigger = None
            else:
                if not op.obj_attr_is_set('trigger'):
                    op.trigger = objects.Trigger(context)
{'fraction_non_alphanumeric': 0.08512820512820513, 'fraction_numerical': 0.0041025641025641026, 'mean_word_length': 2.824313725490196, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1868007', 'n_tokens_mistral': 1333, 'n_tokens_neox': 1339, 'n_words': 391}