## Simplified Report
- Open the attached file, replace the path with a path to any USD file.
- Run the script.
- Blender hits the following assert.
```
BLI_assert failed: source/blender/blenkernel/intern/layer.c:509, BKE_view_layer_copy_data(), at '(view_layer_src->flag & VIEW_LAYER_OUT_OF_SYNC) == 0'
View Layer Object Base out of sync, invoke BKE_view_layer_synced_ensure.
```
{F13591055}
The script is as follows:
```lang=python
import bpy
usd_collection = bpy.data.collections.new("TEST_COLLECTION")
bpy.context.scene.collection.children.link(usd_collection)
layer_collection = bpy.context.view_layer.layer_collection.children['TEST_COLLECTION']
bpy.context.view_layer.active_layer_collection = layer_collection
bpy.ops.wm.usd_import(filepath = "/path/to/any/file.usd", relative_path = False)
```
## Original Report
**System Information**
Operating system: Windows-10-10.0.19041-SP0 64 Bits
Graphics card: NVIDIA GeForce RTX 3090/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 516.59
**Blender Version**
Broken: version: 3.4.0 Alpha, branch: master, commit date: 2022-09-21 22:34, hash: `20dc8393192f`
Worked: version: 3.4.0 Alpha, branch: master, commit date: unknown, hash: `e1a9c16176df` -windows.amd64-release
**Short description of error**
If you create a collection via python, in the code just after that, if you try to make it active, python will throw an error.
I think it must be a recently introduced bug, because you can actually see the collection in the outliner, and if you try the same code ( the make active collection part ) in a separate script execution, the code works.
To help, i suggest that maybe it can be related to recently introduced funcionality of lazy loading here? [[ https://developer.blender.org/rB68589a31ebf | ViewLayer: Lazy sync of scene data]]
I suspect that because i´m trying to access to the viewlayer, and in fact, after executing the code, then you can use the exact same code just commenting the creation part ( collection creation code on the first line just worked ), then it works.
The code:
```
usd_collection = bpy.data.collections.new("TEST_COLLECTION")
bpy.context.scene.collection.children.link(usd_collection)
layer_collection = bpy.context.view_layer.layer_collection.children['TEST_COLLECTION']
bpy.context.view_layer.active_layer_collection = layer_collection
```
**Exact steps for others to reproduce the error**
Just exectute the script in the file attached, it will throw the error. As mentioned above, after the first fail, if you comment the 2 first lines of code and execute it again ( because the collection its already created ) now it works.
It seems to be that the viewlayer isnt accessible even if its already created, like it needs blender to refresh the UI or something?{F13580347}