Commit e36b821
fix: populate draft ChannelVersion metadata during draft publishes (learningequality#5841)
* feat: populate draft ChannelVersion metadata during draft publishes
fill_published_fields now accepts an optional draft_channel_version parameter.
When provided, ChannelVersion-level fields are written to the draft object while
channel-level fields (total_resource_count, published_size, published_data,
version_info) are left untouched. mark_channel_version_as_distributable is also
skipped for draft publishes.
publish_channel now calls fill_published_fields in the draft branch, passing the
draft ChannelVersion returned by create_draft_channel_version.
Closes learningequality#5839
* refactor: simplify draft publish metadata implementation after review
* fix: use queryset update to bypass ChannelVersion full_clean validation
ChannelVersion.save() always calls full_clean(), which validates choices
on ArrayField(IntegerField(choices=...)) for included_licenses. Custom
license IDs used in existing tests (e.g. IDs 100, 101) are not in the
standard choices list from le_utils, so save() raised ValidationError.
Replace version_obj.save() with a queryset .update() to write metadata
fields directly without triggering model-level validation. The data
originates from the DB so validation is unnecessary, and M2M operations
(special_permissions_included) continue to use the model instance.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* refactor: address review feedback on draft publish tests and publish_channel structure
- Merge redundant 'if not is_draft_version:' block into the 'else:' branch of
the is_draft_version conditional in publish_channel, as requested by reviewer.
- Refactor FillPublishedFieldsDraftTestCase into DraftPublishChannelTestCase which
tests the complete publish_channel flow (with save_export_database mocked) rather
than calling fill_published_fields directly. Tests now use a Special Permissions
license node with published=True to exercise the special_permissions_included logic.
- test_second_draft_publish_replaces_special_permissions_included now makes two real
publish_channel calls with different license_description values and verifies the M2M
is replaced (not accumulated) between calls.
- test_mark_channel_version_as_distributable_not_called replaced by
test_special_permissions_distributable_false_for_draft_publish which asserts the
distributable field stays False on the resulting AuditedSpecialPermissionsLicense
objects after a draft publish of a public channel, rather than mocking the method.
* fix: replace channel.included_languages on publish instead of accumulating
Use .set() instead of .add() so languages removed from a channel are
cleared on subsequent publishes rather than accumulated indefinitely.
Flagged by AlexVelezLl, confirmed as a bug by rtibbles.
* fix: use get() instead of create() for Special Permissions license in tests
loadconstants inserts licenses with explicit PKs, leaving the PK sequence
at 1. Calling License.objects.create() in setUp() then collides with the
existing row. Use get() to fetch the pre-existing license — the same
pattern used in test_create_channel_versions.py and test_sync.py.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* fix: move delete_public_channel_cache_keys into else branch of is_draft_version
The previous commit claimed to have merged all 'if not is_draft_version'
blocks into the else branch, but missed the delete_public_channel_cache_keys
call. Move it inside the else block and simplify the condition to 'if
channel.public'.
* fix: revert queryset update to version_obj.save() for ChannelVersion metadata
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
---------
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>1 parent 9247207 commit e36b821
2 files changed
Lines changed: 257 additions & 51 deletions
Lines changed: 203 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
| 9 | + | |
8 | 10 | | |
9 | 11 | | |
10 | 12 | | |
| |||
13 | 15 | | |
14 | 16 | | |
15 | 17 | | |
| 18 | + | |
16 | 19 | | |
17 | 20 | | |
18 | 21 | | |
| |||
176 | 179 | | |
177 | 180 | | |
178 | 181 | | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
915 | 915 | | |
916 | 916 | | |
917 | 917 | | |
918 | | - | |
919 | | - | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
920 | 922 | | |
921 | 923 | | |
922 | 924 | | |
923 | 925 | | |
924 | 926 | | |
925 | | - | |
926 | | - | |
927 | | - | |
| 927 | + | |
928 | 928 | | |
929 | 929 | | |
930 | 930 | | |
931 | 931 | | |
932 | 932 | | |
933 | | - | |
934 | | - | |
| 933 | + | |
935 | 934 | | |
936 | 935 | | |
937 | 936 | | |
| |||
946 | 945 | | |
947 | 946 | | |
948 | 947 | | |
949 | | - | |
950 | | - | |
951 | | - | |
952 | | - | |
953 | 948 | | |
954 | 949 | | |
955 | 950 | | |
| |||
969 | 964 | | |
970 | 965 | | |
971 | 966 | | |
972 | | - | |
973 | | - | |
974 | | - | |
975 | | - | |
976 | | - | |
977 | | - | |
978 | | - | |
979 | | - | |
980 | | - | |
981 | | - | |
982 | | - | |
983 | | - | |
984 | | - | |
985 | | - | |
986 | | - | |
987 | | - | |
988 | | - | |
989 | | - | |
990 | 967 | | |
991 | 968 | | |
992 | 969 | | |
| |||
1030 | 1007 | | |
1031 | 1008 | | |
1032 | 1009 | | |
1033 | | - | |
1034 | | - | |
1035 | | - | |
1036 | | - | |
1037 | | - | |
1038 | | - | |
1039 | | - | |
1040 | | - | |
1041 | | - | |
1042 | | - | |
| 1010 | + | |
| 1011 | + | |
| 1012 | + | |
| 1013 | + | |
| 1014 | + | |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
| 1036 | + | |
| 1037 | + | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
| 1045 | + | |
1043 | 1046 | | |
1044 | 1047 | | |
1045 | | - | |
| 1048 | + | |
1046 | 1049 | | |
1047 | 1050 | | |
1048 | | - | |
| 1051 | + | |
1049 | 1052 | | |
1050 | 1053 | | |
1051 | 1054 | | |
1052 | 1055 | | |
1053 | 1056 | | |
1054 | | - | |
| 1057 | + | |
1055 | 1058 | | |
1056 | | - | |
| 1059 | + | |
1057 | 1060 | | |
1058 | | - | |
| 1061 | + | |
1059 | 1062 | | |
1060 | 1063 | | |
1061 | | - | |
1062 | | - | |
1063 | 1064 | | |
1064 | 1065 | | |
1065 | 1066 | | |
| |||
1161 | 1162 | | |
1162 | 1163 | | |
1163 | 1164 | | |
1164 | | - | |
| 1165 | + | |
| 1166 | + | |
| 1167 | + | |
| 1168 | + | |
1165 | 1169 | | |
1166 | 1170 | | |
1167 | | - | |
1168 | 1171 | | |
1169 | 1172 | | |
1170 | 1173 | | |
| |||
1180 | 1183 | | |
1181 | 1184 | | |
1182 | 1185 | | |
1183 | | - | |
1184 | | - | |
1185 | | - | |
| 1186 | + | |
| 1187 | + | |
| 1188 | + | |
1186 | 1189 | | |
1187 | 1190 | | |
1188 | 1191 | | |
| |||
0 commit comments