Skip to content

Conversation

@beygorghor
Copy link
Collaborator

User should be able to select a sampling result that will be use for assignments step

Related JIRA tickets : IA-4688

Self proofreading checklist

  • Did I use eslint and ruff formatters?
  • Is my code clear enough and well documented?
  • Are my typescript files well typed?
  • New translations have been added or updated if new strings have been introduced in the frontend
  • My migrations file are included
  • Are there enough tests?
  • Documentation has been included (for new feature)

Doc

Changes

  • added selected_sampling_results field to planning model and api + tests
  • update frontend to be able to select a sampling n the table
  • disable assignments link if planning is not published, or if using pipeline we need a selected sample

How to test

Make sure you have sampling generated with samplings, you should be able to select one of those to be use with selected planning

Print screen / video

Screenshot 2026-01-07 at 15 20 14

Follow the Conventional Commits specification

The merge message of a pull request must follow the Conventional Commits specification.

This convention helps to automatically generate release notes.

Use lowercase for consistency.

Example:

fix: empty instance pop up

Refs: IA-3665

Note that the Jira reference is preceded by a line break.

Both the line break and the Jira reference are entered in the Add an optional extended description… field.

Copy link
Member

@quang-le quang-le left a comment

Choose a reason for hiding this comment

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

Minor things front-end side, but it seems to me the serializer needs to be reworked.

Comment on lines 87 to 90
selected_sampling_results_id = serializers.PrimaryKeyRelatedField(
queryset=PlanningSamplingResult.objects.all(), required=False, allow_null=True, write_only=True
)
selected_sampling_results = NestedPlanningSamplingResultSerializer(read_only=True)
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand why you need this. Also it seems weird to me to have a field for both the object and the id of the object

Copy link
Member

Choose a reason for hiding this comment

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

Same thing for me, I don't understand why you have 2 attributes. Is it because you use the same serializer for read and write operations?

beygorghor and others added 3 commits January 8, 2026 11:08
@beygorghor beygorghor requested a review from quang-le January 8, 2026 10:38
Copy link
Member

@quang-le quang-le left a comment

Choose a reason for hiding this comment

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

Just wait for @tdethier opinion on the backend before merging pls

@beygorghor beygorghor force-pushed the IA-4688-selected_sampling_results branch from 4b5d777 to 99d9305 Compare January 8, 2026 11:52
Copy link
Member

@tdethier tdethier left a comment

Choose a reason for hiding this comment

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

Kudos to @quang-le, there's indeed something strange here.

I think the relation type should probably be changed, but the serializer can definitely be simplified!

created_by = models.ForeignKey(User, on_delete=models.SET_NULL, null=True, blank=True)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
selected_sampling_results = models.ForeignKey(
Copy link
Member

Choose a reason for hiding this comment

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

I would use the singular form, since there's a FK to only one object

Copy link
Member

Choose a reason for hiding this comment

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

Additional question: can a PlanningSamplingResult be selected by multiple plannings? It looks like it should be a 1to1 relation, but I'm not sure

Comment on lines 158 to 161
class PlanningWriteSerializer(PlanningSerializer):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields.pop("selected_sampling_results", None)
Copy link
Member

Choose a reason for hiding this comment

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

You do this because you want all fields, except selected_sampling_results?

If so, I would probably use except with __all__ instead, see DRF documentation

Copy link
Member

@tdethier tdethier Jan 8, 2026

Choose a reason for hiding this comment

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

The weird double attributes are probably due to the fact that this serializer inherits from the other one. I would make this one independant (inherit from models.ModelSerializer) and use except and __all__, it will probably simplify everything

Comment on lines 87 to 90
selected_sampling_results_id = serializers.PrimaryKeyRelatedField(
queryset=PlanningSamplingResult.objects.all(), required=False, allow_null=True, write_only=True
)
selected_sampling_results = NestedPlanningSamplingResultSerializer(read_only=True)
Copy link
Member

Choose a reason for hiding this comment

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

Same thing for me, I don't understand why you have 2 attributes. Is it because you use the same serializer for read and write operations?

Comment on lines 151 to 155
def to_representation(self, instance):
data = super().to_representation(instance)
sampling = instance.selected_sampling_results
data["selected_sampling_results"] = NestedPlanningSamplingResultSerializer(sampling).data if sampling else None
return data
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure why you need this either

Comment on lines 199 to 213
def test_selected_sampling_results_field(self):
"""Selected sampling result can be set and read back on planning."""
sampling = PlanningSamplingResult.objects.create(
planning=self.planning,
pipeline_id="pipeline-123",
pipeline_version="v1",
pipeline_name="sample-run",
parameters={"foo": "bar"},
)

self.planning.selected_sampling_results = sampling
self.planning.save()
self.planning.refresh_from_db()

self.assertEqual(self.planning.selected_sampling_results, sampling)
Copy link
Member

Choose a reason for hiding this comment

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

That's not really necessary since there's no custom logic, this test is just testing Django's ORM. We can keep it but it doesn't really bring any value

@beygorghor beygorghor requested a review from tdethier January 9, 2026 09:39
Copy link
Member

@tdethier tdethier left a comment

Choose a reason for hiding this comment

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

Much better now!

There are still a few things that should be done to make sure that the validation is correct (see TODOs in the tests). We'll do that in another PR

@beygorghor beygorghor merged commit 4dc3ec3 into develop Jan 9, 2026
7 checks passed
@beygorghor beygorghor deleted the IA-4688-selected_sampling_results branch January 9, 2026 16:36
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

Successfully merging this pull request may close these issues.

4 participants