From f76181afaea0cadd2fb21f8567338d6d7d787f2c Mon Sep 17 00:00:00 2001 From: Yeray Rodriguez Marco Date: Tue, 13 May 2025 16:32:08 +0200 Subject: [PATCH] Fixing enum filtering --- odata/enumtype.py | 5 +++++ odata/reflect-templates/enum_entity.mako | 2 -- odata/reflector.py | 2 +- odata/state.py | 3 --- poetry.lock | 16 ++++++++-------- pyproject.toml | 2 +- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/odata/enumtype.py b/odata/enumtype.py index 8c032fa..59f8613 100644 --- a/odata/enumtype.py +++ b/odata/enumtype.py @@ -21,6 +21,11 @@ def __init__(self, name, enum_class=EnumType): super(EnumTypeProperty, self).__init__(name) self.enum_class = enum_class + def escape_value(self, value): + if self.enum_class.__module__: + return f"Microsoft.Dynamics.DataEntities.{self.enum_class.__name__}'{value.name}'" + return f"{self.enum_class.__name__}'{value.name}'" + def serialize(self, value): return value.name diff --git a/odata/reflect-templates/enum_entity.mako b/odata/reflect-templates/enum_entity.mako index 23cb22b..bcc2f7c 100644 --- a/odata/reflect-templates/enum_entity.mako +++ b/odata/reflect-templates/enum_entity.mako @@ -1,5 +1,3 @@ - - <%page args="name, entity"/>\ <% short_name = name.split(".")[-1] %>\ ${short_name} = Enum("${short_name}", {\ diff --git a/odata/reflector.py b/odata/reflector.py index e2e5f23..138c8d4 100644 --- a/odata/reflector.py +++ b/odata/reflector.py @@ -94,7 +94,7 @@ "FloatProperty": "float", "BooleanProperty": "bool", "UUIDProperty": "uuid.UUID", - "EnumTypeProperty": "str" + "EnumTypeProperty": "Enum" } diff --git a/odata/state.py b/odata/state.py index 32ffe18..cfe913d 100644 --- a/odata/state.py +++ b/odata/state.py @@ -244,9 +244,6 @@ def _clean_new_entity(self, entity, server_flags: ODataServerFlags): # Deep insert from nav properties for prop_name, prop in es.navigation_properties: - if prop.foreign_key: - insert_data.pop(prop.foreign_key, None) - value = getattr(entity, prop_name, None) """:type : None | odata.entity.EntityBase | list[odata.entity.EntityBase]""" if value is not None: diff --git a/poetry.lock b/poetry.lock index adb2bae..1dff594 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 2.0.1 and should not be changed by hand. +# This file is automatically @generated by Poetry 2.1.3 and should not be changed by hand. [[package]] name = "alabaster" @@ -28,7 +28,7 @@ files = [ pytz = {version = ">=2015.7", markers = "python_version < \"3.9\""} [package.extras] -dev = ["backports.zoneinfo", "freezegun (>=1.0,<2.0)", "jinja2 (>=3.0)", "pytest (>=6.0)", "pytest-cov", "pytz", "setuptools", "tzdata"] +dev = ["backports.zoneinfo ; python_version < \"3.9\"", "freezegun (>=1.0,<2.0)", "jinja2 (>=3.0)", "pytest (>=6.0)", "pytest-cov", "pytz", "setuptools", "tzdata ; sys_platform == \"win32\""] [[package]] name = "certifi" @@ -212,12 +212,12 @@ files = [ zipp = ">=3.20" [package.extras] -check = ["pytest-checkdocs (>=2.4)", "pytest-ruff (>=0.2.1)"] +check = ["pytest-checkdocs (>=2.4)", "pytest-ruff (>=0.2.1) ; sys_platform != \"cygwin\""] cover = ["pytest-cov"] doc = ["furo", "jaraco.packaging (>=9.3)", "jaraco.tidelift (>=1.4)", "rst.linker (>=1.9)", "sphinx (>=3.5)", "sphinx-lint"] enabler = ["pytest-enabler (>=2.2)"] perf = ["ipython"] -test = ["flufl.flake8", "importlib-resources (>=1.3)", "jaraco.test (>=5.4)", "packaging", "pyfakefs", "pytest (>=6,!=8.1.*)", "pytest-perf (>=0.9.2)"] +test = ["flufl.flake8", "importlib-resources (>=1.3) ; python_version < \"3.9\"", "jaraco.test (>=5.4)", "packaging", "pyfakefs", "pytest (>=6,!=8.1.*)", "pytest-perf (>=0.9.2)"] type = ["pytest-mypy"] [[package]] @@ -584,7 +584,7 @@ requests = ">=2.30.0,<3.0" urllib3 = ">=1.25.10,<3.0" [package.extras] -tests = ["coverage (>=6.0.0)", "flake8", "mypy", "pytest (>=7.0.0)", "pytest-asyncio", "pytest-cov", "pytest-httpserver", "tomli", "tomli-w", "types-PyYAML", "types-requests"] +tests = ["coverage (>=6.0.0)", "flake8", "mypy", "pytest (>=7.0.0)", "pytest-asyncio", "pytest-cov", "pytest-httpserver", "tomli ; python_version < \"3.11\"", "tomli-w", "types-PyYAML", "types-requests"] [[package]] name = "rich" @@ -863,7 +863,7 @@ files = [ ] [package.extras] -brotli = ["brotli (>=1.0.9)", "brotlicffi (>=0.8.0)"] +brotli = ["brotli (>=1.0.9) ; platform_python_implementation == \"CPython\"", "brotlicffi (>=0.8.0) ; platform_python_implementation != \"CPython\""] h2 = ["h2 (>=4,<5)"] socks = ["pysocks (>=1.5.6,!=1.5.7,<2.0)"] zstd = ["zstandard (>=0.18.0)"] @@ -882,11 +882,11 @@ files = [ ] [package.extras] -check = ["pytest-checkdocs (>=2.4)", "pytest-ruff (>=0.2.1)"] +check = ["pytest-checkdocs (>=2.4)", "pytest-ruff (>=0.2.1) ; sys_platform != \"cygwin\""] cover = ["pytest-cov"] doc = ["furo", "jaraco.packaging (>=9.3)", "jaraco.tidelift (>=1.4)", "rst.linker (>=1.9)", "sphinx (>=3.5)", "sphinx-lint"] enabler = ["pytest-enabler (>=2.2)"] -test = ["big-O", "importlib-resources", "jaraco.functools", "jaraco.itertools", "jaraco.test", "more-itertools", "pytest (>=6,!=8.1.*)", "pytest-ignore-flaky"] +test = ["big-O", "importlib-resources ; python_version < \"3.9\"", "jaraco.functools", "jaraco.itertools", "jaraco.test", "more-itertools", "pytest (>=6,!=8.1.*)", "pytest-ignore-flaky"] type = ["pytest-mypy"] [metadata] diff --git a/pyproject.toml b/pyproject.toml index c52964b..c190e82 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "python-odata" -version = "0.6.3" +version = "0.6.3.1" description = "A simple library for read/write access to OData services." license="MIT" authors = ["Tuomas Mursu ", "Cristian Libotean "]