Opened 7 months ago

Closed 7 months ago

#35348 closed Bug (needsinfo)

Inconsistent behaviour with annotate using concat and GenericIPAddressField

Reported by: Lorenzo Morandini Owned by: nobody
Component: Database layer (models, ORM) Version: 4.2
Severity: Normal Keywords:
Cc: Lorenzo Morandini Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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'.

Change History (1)

comment:1 by Sarah Boyce, 7 months ago

Resolution: needsinfo
Status: newclosed

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 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 write a regression test which will help verify the issue and make sure it gets resolved quickly.

Note: See TracTickets for help on using tickets.
Back to Top