dapper91 / pydantic-xml

python xml for humans
https://pydantic-xml.readthedocs.io
The Unlicense
141 stars 14 forks source link

fix issue where submodel default namespace is overriden by parent #138

Closed psongers closed 8 months ago

psongers commented 8 months ago

fixes issue #137

dapper91 commented 8 months ago

@psongers Hi

That is the intended behavior that a sub-model inherits the namespace from its parent. But there is indeed a bug: empty entity namespace and empty model namespace are ignored since bool('') is False

the fix should be like this:

if ctx.entity_ns is not None:
    ns = ctx.entity_ns
elif model_cls.__xml_ns__ is not None:
    ns =  model_cls.__xml_ns__ 
else: 
    ctx.parent_ns
psongers commented 8 months ago

@psongers Hi

That is the intended behavior that a sub-model inherits the namespace from its parent. But there is indeed a bug: empty entity namespace and empty model namespace are ignored since bool('') is False

the fix should be like this:

if ctx.entity_ns is not None:
    ns = ctx.entity_ns
elif model_cls.__xml_ns__ is not None:
    ns =  model_cls.__xml_ns__ 
else: 
    ctx.parent_ns

gotchya. that makes sense. I'll update this PR

codecov-commenter commented 8 months ago

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (9e2b126) 91.65% compared to head (2137120) 91.63%.

:exclamation: Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## dev #138 +/- ## ========================================== - Coverage 91.65% 91.63% -0.02% ========================================== Files 25 25 Lines 1366 1375 +9 ========================================== + Hits 1252 1260 +8 - Misses 114 115 +1 ``` | [Flag](https://app.codecov.io/gh/dapper91/pydantic-xml/pull/138/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Dmitry+Pershin) | Coverage Δ | | |---|---|---| | [unittests](https://app.codecov.io/gh/dapper91/pydantic-xml/pull/138/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Dmitry+Pershin) | `91.63% <95.45%> (-0.02%)` | :arrow_down: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Dmitry+Pershin#carryforward-flags-in-the-pull-request-comment) to find out more. | [Files](https://app.codecov.io/gh/dapper91/pydantic-xml/pull/138?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Dmitry+Pershin) | Coverage Δ | | |---|---|---| | [pydantic\_xml/serializers/factories/mapping.py](https://app.codecov.io/gh/dapper91/pydantic-xml/pull/138?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Dmitry+Pershin#diff-cHlkYW50aWNfeG1sL3NlcmlhbGl6ZXJzL2ZhY3Rvcmllcy9tYXBwaW5nLnB5) | `88.75% <100.00%> (ø)` | | | [pydantic\_xml/serializers/factories/model.py](https://app.codecov.io/gh/dapper91/pydantic-xml/pull/138?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Dmitry+Pershin#diff-cHlkYW50aWNfeG1sL3NlcmlhbGl6ZXJzL2ZhY3Rvcmllcy9tb2RlbC5weQ==) | `95.16% <100.00%> (ø)` | | | [pydantic\_xml/serializers/factories/raw.py](https://app.codecov.io/gh/dapper91/pydantic-xml/pull/138?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Dmitry+Pershin#diff-cHlkYW50aWNfeG1sL3NlcmlhbGl6ZXJzL2ZhY3Rvcmllcy9yYXcucHk=) | `80.00% <100.00%> (ø)` | | | [pydantic\_xml/serializers/factories/wrapper.py](https://app.codecov.io/gh/dapper91/pydantic-xml/pull/138?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Dmitry+Pershin#diff-cHlkYW50aWNfeG1sL3NlcmlhbGl6ZXJzL2ZhY3Rvcmllcy93cmFwcGVyLnB5) | `95.12% <100.00%> (ø)` | | | [pydantic\_xml/serializers/serializer.py](https://app.codecov.io/gh/dapper91/pydantic-xml/pull/138?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Dmitry+Pershin#diff-cHlkYW50aWNfeG1sL3NlcmlhbGl6ZXJzL3NlcmlhbGl6ZXIucHk=) | `96.17% <100.00%> (+0.04%)` | :arrow_up: | | [pydantic\_xml/utils.py](https://app.codecov.io/gh/dapper91/pydantic-xml/pull/138?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Dmitry+Pershin#diff-cHlkYW50aWNfeG1sL3V0aWxzLnB5) | `94.87% <100.00%> (+0.75%)` | :arrow_up: | | [pydantic\_xml/serializers/factories/primitive.py](https://app.codecov.io/gh/dapper91/pydantic-xml/pull/138?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Dmitry+Pershin#diff-cHlkYW50aWNfeG1sL3NlcmlhbGl6ZXJzL2ZhY3Rvcmllcy9wcmltaXRpdmUucHk=) | `94.73% <80.00%> (-0.97%)` | :arrow_down: |

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.