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

Add parameter to signal that reorders senses #1461

Open
susanodd opened this issue Jan 20, 2025 · 3 comments
Open

Add parameter to signal that reorders senses #1461

susanodd opened this issue Jan 20, 2025 · 3 comments
Assignees

Comments

@susanodd
Copy link
Collaborator

susanodd commented Jan 20, 2025

Do not reorder senses during API update of senses.

The code currently removes the original senses one by one before adding the replacement senses provided.

gloss.senses.remove(old_sense)

The reorder senses is causing the transaction to fail because of consistency problems because it fires between the deletions.

Make this parametric on whether this originates from the API.

@receiver(m2m_changed, sender=GlossSense)
def post_remove_sense_reorder(sender, instance, **kwargs):
instance.reorder_senses()

@vanlummelhuizen @Woseseltops : THIS IS WHERE THE BUG IS IN API UPDATE SENSES

for sensetrans in sense_translations_this_sense:
translations = sensetrans.translations.all().order_by('orderIndex', 'index')
for index, trans in enumerate(translations, 1):
try:
trans.orderIndex = inx
trans.save()
except (DatabaseError, IntegrityError, TransactionManagementError):

There is an integrity error for some gloss senses.

Hence the fix here #1463 which is a fix for #1360. Also check #1468.

Original code: "update" code should not iteratively remove senses, etc because the "entire" object tree needs to remain consistent.
The reorder senses code is being called "during" the deletion loop.

A solution would be to prevent the "reorder senses" signal from firing "in between" deleting the senses in the update. (Include a preface that it should not do this during the API routine.)

@susanodd
Copy link
Collaborator Author

susanodd commented Jan 20, 2025

Can we just assume we're not using any "shared" senses?

# if this sense is part of another gloss, don't delete it
other_glosses_for_sense = GlossSense.objects.filter(sense=old_sense).exclude(gloss=gloss).count()
if not other_glosses_for_sense:

I'm going to delete this check.

There is also some code that follows that removes example sentences. (The API is only using NGT right now, so since UvA is not using the old style example sentences, I think it's safe to remove that code.)

susanodd pushed a commit that referenced this issue Jan 20, 2025
The code precludes code that adds the updated senses
@susanodd
Copy link
Collaborator Author

See the pull request #1463.

I rewrote the code that removes the original senses to follow a tree traversal pattern to make sure things were deleted properly.

I also removed the gloss's Translation objects.

I also removed code for shared senses (which we have not been using).

This seems to have fixed the consistency problem that led to this issue.

But basically I recoded to avoid the consistency error. The code does not use the GlossSense methods anymore.

@susanodd
Copy link
Collaborator Author

I created this issue because I don't know how to add a parameter to the signal that reorders the senses.

That is needed to add context to whether or not it is needed.

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

No branches or pull requests

2 participants