Skip to content

Commit 4e16bc5

Browse files
authored
Merge pull request #83 from cuenca-mx/fix-enums
Fix IntEnum values
2 parents f6128be + 834be8c commit 4e16bc5

File tree

4 files changed

+23
-9
lines changed

4 files changed

+23
-9
lines changed

.github/workflows/release.yml

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
name: release
22

3-
on: push
3+
on:
4+
release:
5+
types: [published]
46

57
jobs:
6-
publish-pypi:
8+
pypi-publish:
9+
name: Upload release to PyPI
710
runs-on: ubuntu-latest
11+
environment:
12+
name: pypi
13+
url: https://pypi.org/p/mongoengine_plus
14+
permissions:
15+
id-token: write
816
steps:
917
- uses: actions/checkout@master
1018
- name: Set up Python 3.8
@@ -15,9 +23,7 @@ jobs:
1523
run: pip install -qU setuptools wheel twine
1624
- name: Generating distribution archives
1725
run: python setup.py sdist bdist_wheel
18-
- name: Publish distribution 📦 to PyPI
19-
if: startsWith(github.event.ref, 'refs/tags')
20-
uses: pypa/gh-action-pypi-publish@master
26+
- name: Publish package distributions to PyPI
27+
uses: pypa/gh-action-pypi-publish@release/v1
2128
with:
22-
user: ${{ secrets.PYPI_USERNAME }}
23-
password: ${{ secrets.PYPI_PASSWORD }}
29+
user: __token__

mongoengine_plus/models/helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def mongo_to_dict(obj, exclude_fields: list = None) -> dict:
7070
elif isinstance(obj._fields[field_name], DictField):
7171
return_data[field_name] = data
7272
elif isinstance(obj._fields[field_name], EnumField):
73-
return_data[field_name] = data.value if data else None
73+
return_data[field_name] = data.value if data is not None else None
7474
elif isinstance(obj._fields[field_name], LazyReferenceField):
7575
return_data[f'{field_name}_uri'] = (
7676
f'/{data._DBRef__collection}/{data.id}' if data else None

mongoengine_plus/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '0.1.0'
1+
__version__ = '0.1.1'

tests/models/test_helpers.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ class EnumType(Enum):
3030
member = 'name'
3131

3232

33+
class IntEnum(int, Enum):
34+
exito = 0
35+
invalid = 1
36+
37+
3338
class Embedded(EmbeddedDocument):
3439
meta = {'allow_inheritance': True}
3540
name = StringField()
@@ -59,6 +64,7 @@ class TestModel(Document):
5964
lazzy_field = LazyReferenceField(Reference)
6065
lazzy_list_field = ListField(LazyReferenceField(Reference))
6166
generic_lazzy_field = GenericLazyReferenceField()
67+
code = EnumField(IntEnum)
6268

6369
__test__ = False
6470

@@ -71,6 +77,7 @@ def test_mongo_to_dict():
7177
lazzy_list_field=[reference],
7278
embedded_field=Embedded(name='Peter'),
7379
heritage_field=HeritageEmbedded(name='some', lastname='other'),
80+
code=IntEnum.exito,
7481
)
7582
model.save()
7683
model_dict = mongo_to_dict(model, exclude_fields=['str_field'])
@@ -95,3 +102,4 @@ def test_mongo_to_dict():
95102
'name': 'some',
96103
'lastname': 'other',
97104
}
105+
assert model_dict['code'] == 0

0 commit comments

Comments
 (0)