Skip to content

Commit

Permalink
fix: temporary fix to enable serialization of neo4j datetime objects
Browse files Browse the repository at this point in the history
  • Loading branch information
snowpeacock committed Dec 7, 2023
1 parent 3f0586b commit 3695d9e
Showing 1 changed file with 28 additions and 5 deletions.
33 changes: 28 additions & 5 deletions ad_miner/sources/modules/neo4j_class.py
Expand Up @@ -9,7 +9,7 @@
from ad_miner.sources.modules import istarmap # import to apply patch # noqa
import numpy as np
import tqdm
from neo4j import GraphDatabase
import neo4j # TO REPLACE BY 'from neo4j import GraphDatabase' after neo4j fix

from ad_miner.sources.modules import cache_class, logger
from ad_miner.sources.modules.graph_class import Graph
Expand All @@ -19,6 +19,31 @@

MODULES_DIRECTORY = pathlib(__file__).parent

# 🥒 This is a quick import of a fix from @Sopalinge
# 🥒 Following code should be removed when neo4j implements
# 🥒 serialization of neo4j datetime objects
GraphDatabase = neo4j.GraphDatabase


def temporary_fix(cls):
return (
cls.__class__,
(
cls.year,
cls.month,
cls.day,
cls.hour,
cls.minute,
cls.second,
cls.nanosecond,
cls.tzinfo,
),
)


neo4j.time.DateTime.__reduce__ = temporary_fix
# End of temporary dirty fix 🥒


def pre_request(arguments):
driver = GraphDatabase.driver(
Expand Down Expand Up @@ -62,17 +87,15 @@ def pre_request(arguments):
):
number_relations = record.data()["total_relations"]


for record in tx.run(
"MATCH (n) WHERE EXISTS(n.tenantid) return n LIMIT 1"
):
boolean_azure = bool(record.data()['n'])
boolean_azure = bool(record.data()["n"])

driver.close()
print("number relation : ", number_relations)

return extract_date, total_objects, number_relations, boolean_azure

return extract_date, total_objects, number_relations, boolean_azure


class Neo4j:
Expand Down

0 comments on commit 3695d9e

Please sign in to comment.