pythoninfluxdbinfluxdb-pythonaioinflux

Python aioinflux `serialization.usertype.SchemaError: Can't have more than one timestamp-type attribute`, how to avoid it?


I have this dataclass with a lineprotocol schema like this:

from datetime import date, datetime
from aioinflux import lineprotocol, TIMEDT, TAG, FLOAT, MEASUREMENT, STR, INT
from dataclasses import dataclass
from shared import DEBUG_TABLE_NAME


@lineprotocol(
    schema=dict(
        timestamp=TIMEDT,
        measurement=MEASUREMENT,
        target_id=INT,
        type=TAG,
        weight=FLOAT,
        confidence=FLOAT,
        statement=TAG,
        now_time=TIMEDT,
        height=INT,
        dt_time=TIMEDT,
        success=TAG,
    )
)
@dataclass
class DataPoint:
    timestamp: datetime
    target_id: int
    type: str
    weight: float
    confidence: float
    statement: str
    now_time: datetime
    height: int
    dt_time: datetime
    success: str
    measurement: str = DEBUG_TABLE_NAME

but when trying to run the code i get this error: aioinflux.serialization.usertype.SchemaError: Can't have more than one timestamp-type attribute [~TIMEINT, ~TIMEDT, ~TIMESTR]

I still need to have some other attributes like now_time and dt_time in, some short, of time format. But this seems to be raising an error for aioinflux. How can this be avoided?


Solution

  • Valid value types for fields are only: Float, Integer, UInteger, String, Boolean (Reference)

    What you can do, is to store the date either as an integer (timestamp) or a string (RFC3339 format). You can then cast it back in Flux queries, if need be, using:

    1. toTime() to conveniently convert _value
    2. time() to convert single values (e.g., within map())