Opened 3 months ago

Closed 3 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


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(


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

in django 3 main_ip:
in django 4 main_ip:

Is this an expected behaviour? Happens only with concat, an annotate of the ip_address field only produces the output ''.

Change History (1)

comment:1 by Sarah Boyce, 3 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