Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coerce BaseBGPRow attribute values to expected types #313

Merged
merged 4 commits into from
Jul 23, 2024

Conversation

lunkwill42
Copy link
Member

@lunkwill42 lunkwill42 commented Jul 16, 2024

Scope and purpose

Fixes #312.

The issue could also have been fixed by ensuring the assigned types were correct to begin with, or by changing the type annotations of the dataclass to str and ensure the Pydantic model coerces the values instead, but this is my initial suggestion.

Contributor Checklist

Every pull request should have this checklist filled out, no matter how small it is.
More information about contributing to Zino can be found in the
README.

  • Added a changelog fragment for towncrier
  • Added/amended tests for new/changed code
  • Added/changed documentation
  • Linted/formatted the code with black, ruff and isort, easiest by using pre-commit
  • The first line of the commit message continues the sentence "If applied, this commit will ...", starts with a capital letter, does not end with punctuation and is 50 characters or less long. See https://cbea.ms/git-commit/
  • If applicable: Created new issues if this PR does not fix the issue completely/there is further work to be done

Copy link

github-actions bot commented Jul 16, 2024

🦙 MegaLinter status: ✅ SUCCESS

Descriptor Linter Files Fixed Errors Elapsed time
✅ PYTHON black 2 0 0.61s
✅ PYTHON isort 2 0 0.24s
✅ PYTHON ruff 2 0 0.01s

See detailed report in MegaLinter reports
Set VALIDATE_ALL_CODEBASE: true in mega-linter.yml to validate all sources, not only the diff

MegaLinter is graciously provided by OX Security

@lunkwill42 lunkwill42 self-assigned this Jul 16, 2024
@lunkwill42 lunkwill42 marked this pull request as ready for review July 16, 2024 14:45
Copy link

github-actions bot commented Jul 16, 2024

Test results

    3 files      3 suites   1m 17s ⏱️
  511 tests   511 ✅ 0 💤 0 ❌
1 533 runs  1 531 ✅ 2 💤 0 ❌

Results for commit 44e06b8.

♻️ This comment has been updated with latest results.

Copy link

codecov bot commented Jul 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.31%. Comparing base (5fb634d) to head (44e06b8).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #313   +/-   ##
=======================================
  Coverage   97.31%   97.31%           
=======================================
  Files          64       64           
  Lines        7888     7895    +7     
=======================================
+ Hits         7676     7683    +7     
  Misses        212      212           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@lunkwill42 lunkwill42 added the bug Something isn't working label Jul 17, 2024
This requires Pydantic >= 2.7.0, as this is the first version that
enables serialization warnings to be turned into errors/exceptions,
which will trigger this test.
This fixes #312 by type-casting incoming attributes on BaseBGPRow.
The expected Enum types have values designed to match the state strings
from the BGP MIBs, so coercing the strings as early as possible
should do.
While the code works, its always cleaner (and easier to type check)
to refer to the Enum values rather than compare against string
literals (which could be both redundant and incorrect).
@johannaengland johannaengland force-pushed the bugfix/incorrect-bgp-value-types branch from 0d0ff96 to 44e06b8 Compare July 23, 2024 10:38
Copy link

sonarcloud bot commented Jul 23, 2024

@johannaengland johannaengland merged commit cabccad into master Jul 23, 2024
11 checks passed
@johannaengland johannaengland deleted the bugfix/incorrect-bgp-value-types branch July 23, 2024 10:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BGP state monitor sets Event values of incorrect types, causing strange Pydantic serialization errors
2 participants