django-redshift-backend icon indicating copy to clipboard operation
django-redshift-backend copied to clipboard

Add support for Django 4.1

Open fizyk opened this issue 2 years ago • 7 comments

* Strip IDENTITY related suffixes auto fields are getting on Django 4.1.
  These suffixes are upsetting redshift.

Subject: Django 4.1 support

Feature or Bugfix

  • Feature

Purpose

  • Add support for Django 4.1

Detail

  • Clearing DatabaseWrapper.data_types_suffix which, on DJango 4.1, are responsible for adding "GENERATED BY DEFAULT AS IDENTITY" to auto fields, and which are upsetting Redshift. Actually makes impossible to create new table or django_migration table.

Relates

  • #106

fizyk avatar Nov 16 '22 20:11 fizyk

pre-commit is... miscofngured

fizyk avatar Nov 17 '22 12:11 fizyk

Codecov Report

Merging #111 (2042b72) into master (3173766) will decrease coverage by 0.38%. The diff coverage is 100.00%.

:exclamation: Current head 2042b72 differs from pull request most recent head a7b1dc7. Consider uploading reports for the commit a7b1dc7 to get more accurate results

@@            Coverage Diff             @@
##           master     #111      +/-   ##
==========================================
- Coverage   62.38%   61.99%   -0.39%     
==========================================
  Files           3        3              
  Lines         420      421       +1     
  Branches      116      116              
==========================================
- Hits          262      261       -1     
- Misses        116      117       +1     
- Partials       42       43       +1     
Impacted Files Coverage Δ
django_redshift_backend/base.py 62.28% <100.00%> (-0.41%) :arrow_down:

:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more

codecov[bot] avatar Nov 22 '22 19:11 codecov[bot]

Updated documentation and setup.cfg as well

fizyk avatar Nov 24 '22 09:11 fizyk

IDENTITY related suffixes auto fields are getting on Django 4.1

The suffix related to IDENTITY appeared because Django 4.1 now creates AutoField with integer GENERATED BY DEFAULT AS IDENTITY available since postgres 10 instead of serial. https://github.com/django/django/blob/bc3b8f152452ba0e41f28baa93c0bf8f39cddb09/django/db/backends/postgresql/schema.py#L44-L47

Therefore, the current PR will create tables with integer instead of serial, which is a different behavior than in django-4.0 and earlier. I've been investigating for a couple of hours and haven't found a good fix yet. Please let me know if there is a way to fix it.

shimizukawa avatar Nov 26 '22 07:11 shimizukawa

Hmmm... I thought the serial stayed since the tests checked the resulting SQL and without the suffixes it was the same as on earlier Django versions.

fizyk avatar Nov 26 '22 08:11 fizyk

Where should I look? The AutoField data_type was already overriden by redshift-engine to integer identity(1, 1) so i guess somewhere is a part that also needs to be changed for postgresql to either vendor, or ditch the serial in favour of a modern GENERATED BY DEFAULT AS IDENTITY 🤔

fizyk avatar Dec 01 '22 14:12 fizyk

@shimizukawa the way I see it is that the tests running directly on Postgres will become increasingly hard to maintain with each PostgreSQL/Django release (and redshift evolves too).

Maybe the best approach would be to fork the whole code from Django 4.0.x instead of inheriting from the Postgres engine from whatever Django is there underneath. Plus the Postgres implementation and redshift will become increasingly distinct 🤔

I tried to pinpoint what has changed between 4.0.x and 4.1.x but all I got was additional IntegerField generated with primary_key set to True. (copied get_field_type from 4.0.x)

fizyk avatar Dec 01 '22 15:12 fizyk

Thank you @fizyk, I apologize for the long delay. I was able to complete the implementation of django-4.2 support based on your proposal to vend django code base. I'm closing this PR now that Django-4.2 support is complete. Thank you for your great contribution.

shimizukawa avatar Jul 22 '24 21:07 shimizukawa