Skip to content

Commit

Permalink
feat: DIA-957: Delete predictions when ModelVersion updated or ModelR… (
Browse files Browse the repository at this point in the history
#5719)

…un deleted

### PR fulfills these requirements
- [ ] Commit message(s) and PR title follows the format
`[fix|feat|ci|chore|doc]: TICKET-ID: Short description of change made`
ex. `fix: DEV-XXXX: Removed inconsistent code usage causing intermittent
errors`
- [ ] Tests for the changes have been added/updated (for bug
fixes/features)
- [ ] Docs have been added/updated (for bug fixes/features)
- [ ] Best efforts were made to ensure docs/code are concise and
coherent (checked for spelling/grammatical errors, commented out code,
debug logs etc.)
- [ ] Self-reviewed and ran all changes on a local instance (for bug
fixes/features)



#### Change has impacts in these area(s)
_(check all that apply)_
- [ ] Product design
- [ ] Backend (Database)
- [ ] Backend (API)
- [ ] Frontend



### Describe the reason for change
_(link to issue, supportive screenshots etc.)_



#### What does this fix?
_(if this is a bug fix)_



#### What is the new behavior?
_(if this is a breaking or feature change)_



#### What is the current behavior?
_(if this is a breaking or feature change)_



#### What libraries were added/updated?
_(list all with version changes)_



#### Does this change affect performance?
_(if so describe the impacts positive or negative)_



#### Does this change affect security?
_(if so describe the impacts positive or negative)_



#### What alternative approaches were there?
_(briefly list any if applicable)_



#### What feature flags were used to cover this change?
_(briefly list any if applicable)_



### Does this PR introduce a breaking change?
_(check only one)_
- [ ] Yes, and covered entirely by feature flag(s)
- [ ] Yes, and covered partially by feature flag(s)
- [ ] No
- [ ] Not sure (briefly explain the situation below)



### What level of testing was included in the change?
_(check all that apply)_
- [ ] e2e
- [ ] integration
- [ ] unit



### Which logical domain(s) does this change affect?
_(for bug fixes/features, be as precise as possible. ex. Authentication,
Annotation History, Review Stream etc.)_
  • Loading branch information
hakan458 authored Apr 15, 2024
1 parent c7bd01d commit 5c191a2
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion label_studio/ml_models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from ml_model_providers.models import ModelProviderConnection
from projects.models import Project
from rest_framework.exceptions import ValidationError
from tasks.models import Prediction


def validate_string_list(value):
Expand Down Expand Up @@ -54,11 +55,20 @@ class Meta:

parent_model = models.ForeignKey(ModelInterface, related_name='model_versions', on_delete=models.CASCADE)

prompt = models.TextField(_('prompt'), null=False, blank=False, help_text='Prompt to execute')

@property
def full_title(self):
return f'{self.parent_model.title}__{self.title}'

prompt = models.TextField(_('prompt'), null=False, blank=False, help_text='Prompt to execute')
def delete(self, *args, **kwargs):
"""
Deletes Predictions associated with ModelVersion
"""
model_runs = ModelRun.objects.filter(model_version=self.id)
for model_run in model_runs:
model_run.delete_predictions()
super().delete(*args, **kwargs)


class ThirdPartyModelVersion(ModelVersion):
Expand Down Expand Up @@ -159,3 +169,17 @@ def output_file_name(self):
@property
def error_file_name(self):
return f'{self.project.id}_{self.model_version.pk}_{self.pk}/error.csv'

def delete_predictions(self):
"""
Deletes any predictions that have originated from a ModelRun
"""

Prediction.objects.filter(model_run=self.id).delete()

def delete(self, *args, **kwargs):
"""
Deletes Predictions associated with ModelRun
"""
self.delete_predictions()
super().delete(*args, **kwargs)

0 comments on commit 5c191a2

Please sign in to comment.