-
Notifications
You must be signed in to change notification settings - Fork 794
feat: add updates and obsoletes for RFCs #10851
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -571,6 +571,18 @@ class EditableRfcSerializer(serializers.ModelSerializer): | |
| child=SubseriesNameField(required=False), | ||
| write_only=True, | ||
| ) | ||
| updates = serializers.ListField( | ||
| child=serializers.IntegerField(), | ||
| required=False, | ||
| write_only=True, | ||
| help_text="List of RFC numbers this document updates." | ||
| ) | ||
| obsoletes = serializers.ListField( | ||
| child=serializers.IntegerField(), | ||
| required=False, | ||
| write_only=True, | ||
| help_text="List of RFC numbers this document obsoletes." | ||
| ) | ||
|
|
||
| class Meta: | ||
| model = Document | ||
|
|
@@ -584,8 +596,28 @@ class Meta: | |
| "std_level", | ||
| "subseries", | ||
| "keywords", | ||
| "updates", | ||
| "obsoletes", | ||
| ] | ||
|
|
||
| def _validate_rfc_number_list(self, field_name, rfc_numbers): | ||
| """Raise ValidationError if any RFC numbers in the list don't exist.""" | ||
| unknown = [ | ||
| n for n in rfc_numbers | ||
| if not Document.objects.filter(rfc_number=n, type_id="rfc").exists() | ||
| ] | ||
| if unknown: | ||
| raise serializers.ValidationError( | ||
| {field_name: [f"Unknown RFC number: {n}" for n in unknown]} | ||
| ) | ||
| return rfc_numbers | ||
|
|
||
| def validate_updates(self, value): | ||
| return self._validate_rfc_number_list("updates", value) | ||
|
|
||
| def validate_obsoletes(self, value): | ||
| return self._validate_rfc_number_list("obsoletes", value) | ||
|
|
||
| def create(self, validated_data): | ||
| raise RuntimeError("Cannot create with this serializer") | ||
|
|
||
|
|
@@ -602,6 +634,8 @@ def update(self, instance, validated_data): | |
| published = validated_data.pop("published", omitted) | ||
| subseries = validated_data.pop("subseries", omitted) | ||
| authors_data = validated_data.pop("rfcauthor_set", omitted) | ||
| updates = validated_data.pop("updates", omitted) | ||
| obsoletes = validated_data.pop("obsoletes", omitted) | ||
|
|
||
| # Transaction to clean up if something fails | ||
| with transaction.atomic(): | ||
|
|
@@ -673,6 +707,24 @@ def update(self, instance, validated_data): | |
| ) | ||
| ) | ||
| ) | ||
| if updates is not omitted: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For both
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the long run I think DocEvents on the older RFC when a newer one updates or obsoletes it would be a nice thing to have going forward just to make the history easier to read, but to keep things consistent we'd have to back-cast these events for the whole series, and that's not something I think we should bite off right now. So, lets add making them a feature request and move on without adding them now. |
||
| RelatedDocument.objects.filter( | ||
| source=rfc, relationship_id="updates" | ||
| ).exclude(target__rfc_number__in=updates).delete() | ||
| for rfc_num in updates: | ||
| target = Document.objects.get(rfc_number=rfc_num, type_id="rfc") | ||
| RelatedDocument.objects.get_or_create( | ||
| source=rfc, relationship_id="updates", target=target | ||
| ) | ||
| if obsoletes is not omitted: | ||
| RelatedDocument.objects.filter( | ||
| source=rfc, relationship_id="obs" | ||
| ).exclude(target__rfc_number__in=obsoletes).delete() | ||
| for rfc_num in obsoletes: | ||
| target = Document.objects.get(rfc_number=rfc_num, type_id="rfc") | ||
| RelatedDocument.objects.get_or_create( | ||
| source=rfc, relationship_id="obs", target=target | ||
| ) | ||
|
|
||
| # update subseries relations | ||
| if subseries is not omitted: | ||
|
|
||
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.
This is creating a
ValidationErrorthat maps the field name to alistrather than a string. That might work, but I think it should be more like{field_name: f"Unknown RFC number(s): {", ".join(n for n in unknown)}"}