I believe this can be simplified greatly. This is what I came up with (missing return values, BTW):

    def finalize_file(self, project_id, vault_id, file_id, file_size=None):
        """Updates the files table to set a file to finalized. This function
        makes no assumptions about whether or not the file record actually
        exists"""

        # The offset of the first block of *every* file must be zero
        expected_offset = 0

        args = (project_id, vault_id, uuid.UUID(file_id))
        res = self._session.execute(CQL_GET_ALL_FILE_BLOCKS_W_SIZE, args)

        for blockid, offset, size in res:
            if offset == expected_offset:
                expected_offset += size
            elif offset < expected_offset:  # Overlap scenario
                return
            elif offset > expected_offset:  # Gap scenario
                return

        # Now we must check the very last block
        if file_size is not None and file_size <> expected_offset:
            return

        if self.has_file(project_id, vault_id, file_id):
            args = (project_id, vault_id, uuid.UUID(file_id))
            res = self._session.execute(CQL_FINALIZE_FILE, args)