@@ -381,21 +381,33 @@ def check_channel_space(self, channel):
381381 editable_files_qs = self ._filter_storage_billable_files (editable_files_qs )
382382
383383 existing_checksums_cte = With (
384- editable_files_qs .values ("checksum" ).distinct (), name = "existing_checksums"
384+ editable_files_qs .values ("checksum" , "file_format_id" ).distinct (),
385+ name = "existing_checksums" ,
385386 )
386387
387- staging_files_qs = self ._filter_storage_billable_files (
388- self .files .filter (contentnode__tree_id = channel .staging_tree .tree_id )
388+ staging_files_qs = (
389+ user_files_cte .queryset ()
390+ .with_cte (user_files_cte )
391+ .filter (
392+ Exists (
393+ ContentNode .objects .only ("id" ).filter (
394+ tree_id = channel .staging_tree .tree_id ,
395+ id = OuterRef ("contentnode_id" ),
396+ )
397+ )
398+ )
389399 )
390400
401+ staging_files_qs = self ._filter_storage_billable_files (staging_files_qs )
402+
391403 staging_files_qs = (
392404 staging_files_qs .with_cte (tree_cte )
393- .with_cte (user_files_cte )
394405 .with_cte (existing_checksums_cte )
395406 .exclude (
396407 Exists (
397408 existing_checksums_cte .queryset ().filter (
398- checksum = OuterRef ("checksum" )
409+ checksum = OuterRef ("checksum" ),
410+ file_format_id = OuterRef ("file_format_id" ),
399411 )
400412 )
401413 )
0 commit comments