From f76181afaea0cadd2fb21f8567338d6d7d787f2c Mon Sep 17 00:00:00 2001 From: Yeray Rodriguez Marco Date: Tue, 13 May 2025 16:32:08 +0200 Subject: [PATCH 1/4] 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 "] From e8967d79b3a12a49e9a6708a5f7a4e7929cd7f05 Mon Sep 17 00:00:00 2001 From: Yeray Rodriguez Marco Date: Wed, 14 May 2025 15:33:17 +0200 Subject: [PATCH 2/4] Preventing exception for update and insert operations when server_flags attribute is None. --- odata/context.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/odata/context.py b/odata/context.py index f98bb52..4e9c02c 100644 --- a/odata/context.py +++ b/odata/context.py @@ -9,7 +9,7 @@ class Context: - def __init__(self, session=None, auth=None, extra_headers: dict = None, server_flags: ODataServerFlags = None): + def __init__(self, session=None, auth=None, extra_headers: dict = None, server_flags: ODataServerFlags = ODataServerFlags()): self.log = logging.getLogger('odata.context') self.connection = ODataConnection(session=session, auth=auth, extra_headers=extra_headers) self.server_flags = server_flags From ee69b2fe3be7a2897c2e34dd2ddf0991afeccb25 Mon Sep 17 00:00:00 2001 From: Yeray Rodriguez Marco Date: Wed, 14 May 2025 16:22:23 +0200 Subject: [PATCH 3/4] Reverting change for deletion of property key values --- odata/state.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/odata/state.py b/odata/state.py index cfe913d..32ffe18 100644 --- a/odata/state.py +++ b/odata/state.py @@ -244,6 +244,9 @@ 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: From d292d6e4602c050bb58801a66c08789f9928be72 Mon Sep 17 00:00:00 2001 From: Yeray Rodriguez Marco Date: Mon, 16 Mar 2026 13:12:33 +0100 Subject: [PATCH 4/4] Adding action to publish package to pypi --- .github/workflows/publish.yml | 53 +++++++++++++++++++++++++++++++++++ pyproject.toml | 2 +- 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..6a28fbf --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,53 @@ +name: Upload Python Package + +on: + release: + types: [published] + +permissions: + contents: read + +jobs: + release-build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-python@v5 + with: + python-version: "3.12" + + - name: Build release distributions + run: | + python -m pip install build + python -m build + + - name: Upload distributions + uses: actions/upload-artifact@v4 + with: + name: release-dists + path: dist/ + + pypi-publish: + runs-on: ubuntu-latest + needs: + - release-build + permissions: + id-token: write + + environment: + name: pypi + url: https://pypi.org/p/python-odata-nw + + steps: + - name: Retrieve release distributions + uses: actions/download-artifact@v4 + with: + name: release-dists + path: dist/ + + - name: Publish release distributions to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 + with: + packages-dir: dist/ diff --git a/pyproject.toml b/pyproject.toml index c190e82..d9c1330 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [tool.poetry] -name = "python-odata" +name = "python-odata-nw" version = "0.6.3.1" description = "A simple library for read/write access to OData services." license="MIT"