Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StateLog can't handle non-numeric object_id #34

Open
destos opened this issue May 17, 2016 · 34 comments · May be fixed by #97
Open

StateLog can't handle non-numeric object_id #34

destos opened this issue May 17, 2016 · 34 comments · May be fixed by #97

Comments

@destos
Copy link

destos commented May 17, 2016

Ran into this issue when attempting to log state changes on a model that uses Postgres uuid4 fields for the primary key.

@tysonclugg
Copy link

Thanks for the report @destos. 😃

Looking through https://docs.djangoproject.com/en/1.8/ref/contrib/contenttypes/#generic-relations in the section titled "Primary key type compatibility" I found this:

There is no one-size-fits-all solution for which field type is best. You should evaluate the models you expect to be pointing to and determine which solution will be most effective for your use case.

Perhaps the solution is something along the lines of using class inheritance from the StateLog model and overriding the object_id field, then allow passing statelog_model='myapp.FooStateLog' or similar to your FSMField.

Did you want to start a PR?

@seocam
Copy link

seocam commented May 19, 2016

I'm also affected by this issue. Still I'm not sure how to solve it since I'm using FSM with numeric and non-numeric ids.

@destos
Copy link
Author

destos commented May 19, 2016

I can probably take a look at a fix today per your suggestion.

@seocam
Copy link

seocam commented May 19, 2016

The CharField is flexible enough to take UUIDs. Primary Keys as UUIDs are very useful in systems using DB replication.

@ticosax
Copy link
Member

ticosax commented Nov 9, 2017

I tend to lean towards a similar proposal, maybe with a swappable Model ?
At least we shouldn't force existing users to migrate/change type of object_id field.

@dbinetti
Copy link

So glad this repo is getting some love @ticosax Am really hoping that UUID support for PKs can be added, in whatever form; this is really become the norm these days.

@dbinetti
Copy link

dbinetti commented Jan 5, 2018

Happy New Year! What is the status of this issue? Do you need additional feedback on it @ticosax? I'm still using a fork but would love to get back on the main repo.

@ticosax
Copy link
Member

ticosax commented Jan 5, 2018

@dbinetti Pull requests are welcome. Unfortunately, I don't have myself the need for this use case, so I don't have economical incitement to do it. Suggestions of a suitable approach has been made by @tysonclugg and me. I will help as much as I can once a PR with decent coverage is made.

@dbinetti
Copy link

dbinetti commented Jan 6, 2018

Very well. My fork just runs a migration to CharField; I'm afraid creating swappable models is beyond my skills. I'll just pull from upstream. Thanks!

@riparian-imakedonsky
Copy link

Also affected by this issue(we have UUID's as ids). Will copy-paste model to the project with field type changed.
Would be great to just transition to CharField intead, should work seamlessly for anyone.

@josh-stableprice
Copy link

josh-stableprice commented May 29, 2019

I tend to lean towards a similar proposal, maybe with a swappable Model ?
At least we shouldn't force existing users to migrate/change type of object_id field.

Please, don't do a swappable model. They're literally more hassle than they're worth based on my experience with django-cities. You have to make the decision to use a swapped model from the start of the project or you're totally stuck, unable to migrate to/away from it. Either way it's a migration and if done correctly, should be seamless the way it's been suggested above.

Given that the issue at hand here can be resolved so simply by using a CharField to allow integer and uuid primary keys, the thought of using a swappable model is pure overkill. Also, I keep coming back to this issue every so often to see if anyone has just merged PR #48.

@tysonclugg
Copy link

Given that the issue at hand here can be resolved so simply by using a CharField to allow integer and uuid primary keys, the thought of using a swappable model is pure overkill. Also, I keep coming back to this issue every so often to see if anyone has just merged PR #48.

Not so simple when you consider that using a CharField would require all users to migrate.

Also, quoting the Django docs again:

There is no one-size-fits-all solution for which field type is best.

@ticosax
Copy link
Member

ticosax commented Jul 3, 2019

Please, don't do a swappable model.

Thanks for your feedback. What are the alternatives ? given that asking everyone else to migrate to a CharField is a no go in my opinion. The solution shouldn't be intrusive.

@josh-stableprice
Copy link

How is the migration to a Charfield for the statelog table intrusive? All users will have to migrate anyway if you start using a Swappable field, which in my project has been nothing but pain. I get constantly asked to migrate my project and every time I run makemigrations it creates another migration that does the exact same no-op each time. Packages create new migrations for their users all the time, so I'm unsure where the intrusion is here?

@ticosax
Copy link
Member

ticosax commented Jul 15, 2019

by intrusive I meant changing the type of the DB column for projects that doesn't want/care about. You shared your experience with swappable models and explain it is not a good idea. Fine, how do we move forward ? There is probably other solutions out there ?

@dbinetti
Copy link

dbinetti commented Jul 15, 2019 via email

@ticosax
Copy link
Member

ticosax commented Jul 15, 2019

People who doesn't want to migrate, doesn't fork. We can't measure how many they are. If your suggestion would be merged, I (as an example) would fork the project to keep the FK as an Integer.
Either way, we stay divided.

@dbinetti
Copy link

dbinetti commented Jul 15, 2019 via email

@josh-stableprice
Copy link

josh-stableprice commented Jul 16, 2019 via email

@dbinetti
Copy link

No one is suggesting that the reference fields need to be changed. @ticosax 's point is that mandating a migration is itself an intrusion. Now we can argue about whether or not that rises to the level of an impassable burden (I personally think not) but it is certainly an imposition on existing users who have no need to support non-numeric PKs.

@mr-bo-jangles
Copy link

mr-bo-jangles commented Jul 16, 2019

but it is certainly an imposition on existing users who have no need to support non-numeric PKs.

How. What use case, supported by this library, are we breaking by introducing these changes.

@dbinetti
Copy link

dbinetti commented Jul 16, 2019 via email

@josh-stableprice
Copy link

josh-stableprice commented Jul 17, 2019 via email

@dbinetti
Copy link

Yep, sounds totally reasonable.

What say ye @ticosax? Are you persuaded by this discussion? I think we can put together a PR if we believed it had a chance of being merged.

@ticosax
Copy link
Member

ticosax commented Jul 17, 2019

At this point, I'm no longer interested into maintaining this library.
I'd like to step down from my maintainer and releaser role.
It doesn't mean I will stop contributing, but this decision is a burden I'm not willing to take.

Any candidate ?

@jacobh @tysonclugg, please, take it over from there. I don't have permission to invite new maintainers.

@ticosax
Copy link
Member

ticosax commented Jul 17, 2019

no need to be so dramatic, luckily there is other maintainers.

@mr-bo-jangles
Copy link

Dramatic?

@ticosax
Copy link
Member

ticosax commented Jul 18, 2019

Dramatic ?

I was referring to my previous comment. Luckily, there is other people who could step in.

@tysonclugg
Copy link

My tenure at Gizmag is drawing to a close within the next month, as is the tenure of the Gizmag Django codebase. I'm happy enough to hand this project over to new maintainers, and move to a new organisation. I'll raise a new issue asking for new maintainers.

@josh-stableprice
Copy link

I've made a PR to cover these changes as #97.

@ddahan
Copy link

ddahan commented Sep 9, 2022

At this point, after reading the whole conversation, it's still not clear to me if there is a workaround which does not imply a fork?

Anyway, as long as the PR about this topic in not merged, I think it could be valuable to add the "gotcha" in the documentation about this topic (and potentially the workaround I mentioned if it works, even if it's not perfect.)

@ddahan
Copy link

ddahan commented Sep 9, 2022

And about the drama of forcing a user to migrate or not by changing the object_id type, perhaps the solution could be to use an optional setting in settings.py file. It may be an anti-pattern, but in projects like django-cities, defining a specific setting and then, running migrations produces different output.

I would expect that:

  • old users are not not affected, as they will never define a setting in their settings.py file.
  • new users are able to use charfield type, just by adding a statement like FSM_LOG_USE_CHARFIELD = True in settings.py and running migrations after that.

@ticosax
Copy link
Member

ticosax commented Sep 12, 2022

There is a proposal.
#133
Where django-fsm-log would become stateless, where each app will be responsible to maintain their migrations and concrete models, while django-fsm-log provide only the abstract model & the plumbing code.
Do you think it could work for your use case ?

@ddahan
Copy link

ddahan commented Sep 12, 2022

To be honest, my workaround was simply to manage to have two kinds of ids (int + charfield/uuid) to my project, and then choosing which one to use according the context.

So I can say I don't have the problem anymore. I'll answer to your proposal anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants