salesforce / logai

LogAI - An open-source library for log analytics and intelligence
BSD 3-Clause "New" or "Revised" License
438 stars 64 forks source link

ValueError(f'mutable default {type(f.default)} for field #62

Open Jeayea opened 1 year ago

Jeayea commented 1 year ago

when running python ./gui/application.py in the directory~/logai, an error occurred.

Traceback (most recent call last):
  File "~/logai/./gui/application.py", line 16, in <module>
    from gui.callbacks import pattern, anomaly_detection, clustering, utils
  File "~/logai/gui/callbacks/pattern.py", line 15, in <module>
    from logai.applications.application_interfaces import (
  File "~/logai/logai/applications/application_interfaces.py", line 10, in <module>
    from logai.analysis.anomaly_detector import AnomalyDetectionConfig
  File "~/logai/logai/analysis/anomaly_detector.py", line 9, in <module>
    import logai.algorithms.anomaly_detection_algo
  File "~/logai/logai/algorithms/anomaly_detection_algo/__init__.py", line 8, in <module>
    from .dbl import DBLDetector
  File "~logai/logai/algorithms/anomaly_detection_algo/dbl.py", line 16, in <module>
    from logai.algorithms.algo_interfaces import AnomalyDetectionAlgo
  File "~/logAly/logai/logai/algorithms/algo_interfaces.py", line 11, in <module>
    from logai.dataloader.data_model import LogRecordObject
  File "~/logAly/logai/logai/dataloader/data_model.py", line 17, in <module>
    @dataclass
     ^^^^^^^^^
  File "~/miniconda3/envs/logaiEnv/lib/python3.11/dataclasses.py", line 1230, in dataclass
    return wrap(cls)
           ^^^^^^^^^
  File "~/miniconda3/envs/logaiEnv/lib/python3.11/dataclasses.py", line 1220, in wrap
    return _process_class(cls, init, repr, eq, order, unsafe_hash,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~/miniconda3/envs/logaiEnv/lib/python3.11/dataclasses.py", line 958, in _process_class
    cls_fields.append(_get_field(cls, name, type, kw_only))
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~/miniconda3/envs/logaiEnv/lib/python3.11/dataclasses.py", line 815, in _get_field
    raise ValueError(f'mutable default {type(f.default)} for field '
ValueError: mutable default <class 'pandas.core.frame.DataFrame'> for field timestamp is not allowed: use default_factory
jvalenzuelasanz commented 1 year ago

I have the same error because my default python is version 3.11.4 (and the raised error based on documentation of Dataclasses is related with new controls included on 3.11)

To avoid this, instead to create venv as proposed, I've created it with conda:

conda create --name logai python=3.9

After environment creation you must activate it using:

conda activate logai

Into it, the installed python version (on my case at least) is 3.9.18

Go to your downloaded logai directory and as requested from there execute pip:

pip install logai (and [all]

markman623 commented 8 months ago

I have this same error also, any way to resolve this withoug conda?

markman623 commented 8 months ago

I fixed this! In data_model.py, the LogRecordObject properties should look like this:
Original pd.DataFrame = pd.DataFrame() Fixed: timestamp: pd.DataFrame = field(default_factory=pd.DataFrame)

cai-zhuo commented 8 months ago

I fixed this! In data_model.py, the LogRecordObject properties should look like this: Original pd.DataFrame = pd.DataFrame() Fixed: timestamp: pd.DataFrame = field(default_factory=pd.DataFrame)

@markman623 Many thanks for advising. I just tried and executed python3 gui/application.py, but it still doesn't work. What else should I do ?

markman623 commented 8 months ago

Did you do that for all properties? Should look like this: timestamp: pd.DataFrame = field(default_factory=pd.DataFrame) attributes: pd.DataFrame = field(default_factory=pd.DataFrame) resource: pd.DataFrame = field(default_factory=pd.DataFrame) trace_id: pd.DataFrame = field(default_factory=pd.DataFrame) span_id: pd.DataFrame = field(default_factory=pd.DataFrame) severity_text: pd.DataFrame = field(default_factory=pd.DataFrame) severity_number: pd.DataFrame = field(default_factory=pd.DataFrame) body: pd.DataFrame = field(default_factory=pd.DataFrame) labels: pd.DataFrame = field(default_factory=pd.DataFrame)

What error exactly are you getting?

cai-zhuo commented 8 months ago

Did you do that for all properties? Should look like this: timestamp: pd.DataFrame = field(default_factory=pd.DataFrame) attributes: pd.DataFrame = field(default_factory=pd.DataFrame) resource: pd.DataFrame = field(default_factory=pd.DataFrame) trace_id: pd.DataFrame = field(default_factory=pd.DataFrame) span_id: pd.DataFrame = field(default_factory=pd.DataFrame) severity_text: pd.DataFrame = field(default_factory=pd.DataFrame) severity_number: pd.DataFrame = field(default_factory=pd.DataFrame) body: pd.DataFrame = field(default_factory=pd.DataFrame) labels: pd.DataFrame = field(default_factory=pd.DataFrame)

What error exactly are you getting?

@markman623 Sorry, Im a python noob, It worked after tried this. Thank You!

markman623 commented 8 months ago

Great! Glad I could help :-) I'm also a noob so was excited when I actually fixed something :-)