-
Notifications
You must be signed in to change notification settings - Fork 9
feat: add uniqueness field validation for span questions #60
feat: add uniqueness field validation for span questions #60
Conversation
7dbc917
to
cfb72e5
Compare
for more information, see https://pre-commit.ci
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## feat/support-for-span-questions #60 +/- ##
================================================================
Coverage 90.33% 90.33%
================================================================
Files 189 189
Lines 9289 9292 +3
================================================================
+ Hits 8391 8394 +3
Misses 898 898 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. I added some comments in the case that you want to improve it a little bit.
@@ -120,6 +120,10 @@ def _validate_span_question_settings_before_create( | |||
if field not in field_names: | |||
raise ValueError(f"'{field}' is not a valid field name.\nValid field names are {field_names!r}") | |||
|
|||
for question in dataset.questions: | |||
if question.type == QuestionType.span and field == question.parsed_settings.field: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I already added in one commit a property to Question
database model to check if if span or not. But after some changes I removed it because I was not using it.
Take a look to the commit here: 799743b#diff-b7efe64daa88a5d7c98088e2a66d38739605226e60d4ed967712ca2790c54931
If you want to apply that change then you can do:
if question.type == QuestionType.span and field == question.parsed_settings.field: | |
if question.is_span and field == question.parsed_settings.field: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer to keep it as is. We already have other places using this kind of condition with settings directly and it can be confusing seeing is_span
or settings.type == QuestionType.span
depending on the context.
We can review it later when using question validators. However, migrating the project to Python 3.10 and using the pattern-matching switch would be a better option.
Co-authored-by: José Francisco Calvo <jose@argilla.io>
1d9c1f1
into
feat/support-for-span-questions
Description
This PR adds a server validation to avoid creating several span questions using the same field.
Type of change
(Please delete options that are not relevant. Remember to title the PR according to the type of change)
How Has This Been Tested
(Please describe the tests that you ran to verify your changes. And ideally, reference
tests
)Checklist
CHANGELOG.md
file (See https://keepachangelog.com/)