EandrewJones commented on code in PR #50: URL: https://github.com/apache/flagon-distill/pull/50#discussion_r1677967100
########## distill/core/log.py: ########## @@ -34,27 +34,33 @@ class Log: defaults to UserAle log schema """ - def __init__(self, data: Union[str, JsonDict], schema=UserAleSchema): - if not issubclass(schema, BaseModel): + def __init__(self, data: Union[str, JsonDict], schema=None): + if schema is None: + schema = UserAleSchema + elif issubclass(schema, BaseModel): raise TypeError("schema should inherit from pydantic.BaseModel") if isinstance(data, str): - schema.model_validate_json(data, strict=True) + # schema.model_validate_json(data, strict=True) Review Comment: why commented out? Remove. ########## distill/schemas/useralebase.py: ########## @@ -0,0 +1,57 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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 datetime import datetime +from typing import List, Optional + +from pydantic import BaseModel, Field +from pydantic.alias_generators import to_camel + +from .base import BaseSchema Review Comment: Relative imports are fragile and harder for IDEs to auto-update. Make absolutel. ########## distill/core/log.py: ########## @@ -34,27 +34,33 @@ class Log: defaults to UserAle log schema """ - def __init__(self, data: Union[str, JsonDict], schema=UserAleSchema): - if not issubclass(schema, BaseModel): + def __init__(self, data: Union[str, JsonDict], schema=None): + if schema is None: + schema = UserAleSchema + elif issubclass(schema, BaseModel): raise TypeError("schema should inherit from pydantic.BaseModel") if isinstance(data, str): - schema.model_validate_json(data, strict=True) + # schema.model_validate_json(data, strict=True) hash_sfx = str(hash(data)) data = json.loads(data) elif ta.validate_python(data): hash_sfx = str(hash(json.dumps(data))) - schema.model_validate(data, strict=True) + # schema.model_validate(data, strict=True) else: - raise TypeError("ERROR: " + str(type(data)) + " data should be either a string or a JsonDict") - self.data = schema(**data) - - self.id = PKSUID("log_" + hash_sfx, schema._timestamp(self.data)) + raise TypeError( + "ERROR: " + + str(type(data)) + + " data should be either a string or a JsonDict" + ) + # self.data = schema(**data) + self.data = schema.validate_python(data) + # self.id = PKSUID("log_" + hash_sfx, schema._timestamp(self.data)) Review Comment: remove. ########## distill/core/log.py: ########## @@ -34,27 +34,33 @@ class Log: defaults to UserAle log schema """ - def __init__(self, data: Union[str, JsonDict], schema=UserAleSchema): - if not issubclass(schema, BaseModel): + def __init__(self, data: Union[str, JsonDict], schema=None): + if schema is None: + schema = UserAleSchema + elif issubclass(schema, BaseModel): raise TypeError("schema should inherit from pydantic.BaseModel") if isinstance(data, str): - schema.model_validate_json(data, strict=True) + # schema.model_validate_json(data, strict=True) hash_sfx = str(hash(data)) data = json.loads(data) elif ta.validate_python(data): hash_sfx = str(hash(json.dumps(data))) - schema.model_validate(data, strict=True) + # schema.model_validate(data, strict=True) Review Comment: Remove. ########## distill/core/log.py: ########## @@ -34,27 +34,33 @@ class Log: defaults to UserAle log schema """ - def __init__(self, data: Union[str, JsonDict], schema=UserAleSchema): - if not issubclass(schema, BaseModel): + def __init__(self, data: Union[str, JsonDict], schema=None): + if schema is None: + schema = UserAleSchema + elif issubclass(schema, BaseModel): raise TypeError("schema should inherit from pydantic.BaseModel") if isinstance(data, str): - schema.model_validate_json(data, strict=True) + # schema.model_validate_json(data, strict=True) hash_sfx = str(hash(data)) data = json.loads(data) elif ta.validate_python(data): hash_sfx = str(hash(json.dumps(data))) - schema.model_validate(data, strict=True) + # schema.model_validate(data, strict=True) else: - raise TypeError("ERROR: " + str(type(data)) + " data should be either a string or a JsonDict") - self.data = schema(**data) - - self.id = PKSUID("log_" + hash_sfx, schema._timestamp(self.data)) + raise TypeError( + "ERROR: " + + str(type(data)) + + " data should be either a string or a JsonDict" + ) + # self.data = schema(**data) Review Comment: remove, -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@flagon.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@flagon.apache.org For additional commands, e-mail: notifications-h...@flagon.apache.org