[Django] #35348: Inconsistent behaviour with annotate using concat and GenericIPAddressField

9 views
Skip to first unread message

Django

unread,
Apr 2, 2024, 5:22:19 AM4/2/24
to django-...@googlegroups.com
#35348: Inconsistent behaviour with annotate using concat and GenericIPAddressField
-------------------------------------+-------------------------------------
Reporter: Lorenzo | Owner: nobody
Morandini |
Type: Bug | Status: new
Component: Database | Version: 4.2
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Concat function behaviour changed from django 3 to django 4 together with
GenericIPAddressField. In django 3 it would output only the ip address,
now a /32 is included too by default

Example model

{{{
class Example(models.Model):
ip_address = models.GenericIPAddressField(
_('ip address'), db_index=True, protocol='IPv4'
)
mask = models.PositiveIntegerField(
_('mask'),
)

Example.objects.all()
.annotate(
main_ip=Concat(
'ip_address',
V('/')
'mask'
)
)
}}}

With an example item with ip 192.168.1.1 and mask 30 the output would be:

in django 3 main_ip: 192.168.1.1/30
in django 4 main_ip: 192.168.1.1/32/30

Is this an expected behaviour? Happens only with concat, an annotate of
the ip_address field only produces the output '192.168.1.1'.
--
Ticket URL: <https://code.djangoproject.com/ticket/35348>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Apr 2, 2024, 6:52:09 AM4/2/24
to django-...@googlegroups.com
#35348: Inconsistent behaviour with annotate using concat and GenericIPAddressField
-------------------------------------+-------------------------------------
Reporter: Lorenzo Morandini | Owner: nobody
Type: Bug | Status: closed
Component: Database layer | Version: 4.2
(models, ORM) |
Severity: Normal | Resolution: needsinfo
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce):

* resolution: => needsinfo
* status: new => closed

Comment:

Hi Lorenzo, thank you for this report.

I am struggling to replicate this locally and need a few more details. To
help me, please provide:
- what database are you using
- what version of Python are you using
- did you upgrade Python when upgrading from Django 3.2 to 4.2

We use
[https://docs.python.org/3/library/ipaddress.html#ipaddress.IPv4Network
ipaddress] from the Python standard library and `/32` is documented as a
default mask for `IPv4Network`, hence the version of Python might be
important here and whether this changed while upgrading.

If you want to make my day, you could
[https://docs.djangoproject.com/en/5.0/internals/contributing/writing-code
/unit-tests/#unit-tests write a regression test] which will help verify
the issue and make sure it gets resolved quickly.
--
Ticket URL: <https://code.djangoproject.com/ticket/35348#comment:1>
Reply all
Reply to author
Forward
0 new messages