Skip to content

Remove custom get_or_create method, fixes #1700 - #1701

Open
Fingel wants to merge 2 commits into
hash-flux-unique-constraintfrom
1700-remove-custom-get-or-create
Open

Fingel wants to merge 2 commits into
hash-flux-unique-constraintfrom
1700-remove-custom-get-or-create

Conversation

@Fingel

@Fingel Fingel commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

No description provided.

@Fingel
Fingel requested a review from jchate6 October 14, 2026 21:14
@Fingel Fingel linked an issue Oct 14, 2026 that may be closed by this pull request

@jchate6 jchate6 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have a test for trying to get_or_create an object where the unique constraints are identical but fields that are not checked for uniqueness differ?
I'm still concerned that without something like this, get_or_create will fail to get because they are too different, but also fail to create because they are too similiar.

What should happen in that case?

@Fingel

Fingel commented Oct 14, 2026

Copy link
Copy Markdown
Contributor Author

I still don't follow. If get_or_create() fails to create because of a uniqueness check, how is that different than just .create()? It should fail, even if the non-indexed columns differ. And it should also not return an existing object, if the non-indexed fields are different. I think in the case you are thinking of, you just don't pass in the non-indexed fields? There is no requirement to pass in every field to get_or_create.

@jchate6

jchate6 commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

I think I disagree. It feels like if two objects are so similar that we would not create a new one, I would want the get_or_create to return to me the one that is similar. Also, not passing the non-indexed fields prevents me from creating my full object with that command, and fundamentally changes the use and expected behavior for get_or_create in tomtoolkit.
I basically HAVE to wrap every get_or_create in a try/except.

@jchate6 jchate6 moved this to Needs Review in TOM Toolkit Oct 16, 2026
@jchate6
jchate6 changed the base branch from dev to hash-flux-unique-constraint October 16, 2026 16:48
@jchate6
jchate6 added this pull request to stack #1703 October 16, 2026 16:52
@Fingel

Fingel commented Oct 16, 2026

Copy link
Copy Markdown
Contributor Author

get_or_create to return to me the one that is similar

This sounds like you are describing a heuristic, not how get or create normally works. We can write this as a different method, but I wouldn’t override it. I think would be fine as domain specific logic at the call site instead of overriding Django built ins.

@jchate6
jchate6 force-pushed the 1700-remove-custom-get-or-create branch from c0fe653 to ea8c44c Compare October 16, 2026 17:17

@jchate6 jchate6 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense. I guess I'd like to see some tests that run this scenario for the places we rely on get_or_create in the code.

@Fingel

Fingel commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

I added a few tests which look like how get_or_create is used in the alerce broker:

def process_reduced_data(self, target, alert=None):

Though it doesn't really feel like the specific case the overriden method was designed for. I couldn't find any calls in tom_base that look like they were, maybe in an external app?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Needs Review

Development

Successfully merging this pull request may close these issues.

*ReducedDatum.objects.get_or_create can raise ValidationError

2 participants