djangosaml2idp icon indicating copy to clipboard operation
djangosaml2idp copied to clipboard

Make the models swappable

Open lgarvey opened this issue 3 years ago • 6 comments

This PR follows the pattern used in django-oauth2-toolkit - and is suggested in #90

I have a need to extend the ServiceProvider model to add some additional features so I thought I'd raise a PR to add swappable functionality. I can also add some documentation if required.

I assume unit tests aren't required as it's leveraging the swappable api in django?

lgarvey avatar Mar 02 '21 18:03 lgarvey

Hi @mhindery I've squashed the previous migrations and used the squashed version to apply the swappable logic. So that existing installations should still function without any issues.

Doing some manual testing the PR works with:

an existing installation of djangosaml2idp with previous migrations applied a new installation of djangosaml2idp without overridden models a new installation of djangosaml2idp with overridden models (will do some more testing as currently I have only overridden the ServiceProvider model)

I haven't looked at the admin system - but typically this involves unregistering and re-registering the admin models in the overriding app.

It'd be good to gauge whether you'd be interested in merging the PR as I'm currently building some functionality that depends on it. Essentially I need to add some extra fields to the ServiceProvider model

lgarvey avatar Mar 03 '21 15:03 lgarvey

Hi @lgarvey , this is a great addition, I'm definitely happy to merge this in.

mhindery avatar Mar 06 '21 13:03 mhindery

Ideally this gets some documentation added as well, but that is something I can add later. Let me know if you are done and not plan any more changes in the PR, then I'll merge it.

mhindery avatar Mar 06 '21 17:03 mhindery

It all seems good from this end - one very minor point:

If overriding a model, the migration for the overridden model has to run before the migrations for djangosaml2idp or else there'll be an error. The django-oauth-toolkit advises to put a run_before statement into your overriding migration to ensure they are executed in the correct order, e.g

class Migration(migrations.Migration):

    run_before = [
        ('djangosaml2idp', '0001_initial_squashed_0002_persistent_id_swappable_models'),
    ]

I think the name of the squashed (and swappable) migration should be something less verbose, e.g: 0001_initial_swappable.py

But aside from that everything seems good.

lgarvey avatar Mar 06 '21 17:03 lgarvey

This seems all good to merge now.

lgarvey avatar Mar 08 '21 15:03 lgarvey

Hello,

Is there any reason why this PR has not been merged in upstream?

farzeni avatar Feb 07 '22 09:02 farzeni