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

fields: replace IPy dependency with ipaddress module #293

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

johnnyapol
Copy link

Resolves #229

@johnnyapol
Copy link
Author

I ran the tests in the README and addressed the failure (python3's ipaddress module gave a different assertion).

Please let know if you would like to see any additional regression tests, documentation, etc.

@jelly
Copy link
Member

jelly commented Aug 3, 2020

We have IP addresses that don't work with ipaddress module such as:

>>> print(ip_address('2a0b:4342:1a31:410::/64'))                                                                                                                         
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.8/ipaddress.py", line 53, in ip_address
    raise ValueError('%r does not appear to be an IPv4 or IPv6 address' %
ValueError: '2a0b:4342:1a31:410::/64' does not appear to be an IPv4 or IPv6 address

@johnnyapol
Copy link
Author

johnnyapol commented Aug 4, 2020

I see, I didn't see #276 when I took a look at this.

My fix was to check if '/' existed in the string. If no mask exists, then we just call ip_address like normal. Otherwise, we call into ip_interface, which handles those cases.

Although, this won't work if we're inputting the addresses in a non-string format. If that's an issue, a simple workaround can be to guard the call to ip_address with a try: block and then call into ip_interface as a backup

@jelly
Copy link
Member

jelly commented Sep 6, 2021

Also interesting a ipaddressfield is now available in Django but that might not work as it lacks the hostmask.

@johnnyapol
Copy link
Author

johnnyapol commented Sep 6, 2021

@jelly I just rebased this if you want to take another look. Hostmasks do work in this PR now (and tests were added to avoid regressions)

@jelly
Copy link
Member

jelly commented Sep 12, 2021

@jelly I just rebased this if you want to take another look. Hostmasks do work in this PR now (and tests were added to avoid regressions)

Thanks a lot, taking a look at testing the changes / impact locally!

@jelly
Copy link
Member

jelly commented Sep 12, 2021

Tested by creating a new rsync ipv6 address in the django admin interface causes:

    if '/' not in address:
TypeError: argument of type 'IPv6Interface' is not iterable

In https://archweb.lxd/admin/mirrors/mirror/214/change/

Same for a ipv4 address:

  File "/home/jelle/projects/archweb/mirrors/fields.py", line 37, in to_python
    return IP(value)
  File "/home/jelle/projects/archweb/mirrors/fields.py", line 9, in IP
    if '/' not in address:
TypeError: argument of type 'IPv4Address' is not iterable

Copy link
Member

@jelly jelly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Saving a mirror with a mirrorrsync ip address throws an exception

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Switch IPy to Python3's ipaddress
2 participants