loopbackio / loopbackio/loopback-next

Regression: secondary HasManyThrough inclusion fails with circular dependency

Đang mở
#7,599 23 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

bug IoC/Context needs grooming Repository
Ngôn ngữ chính
TypeScript
Star
5.1k
Fork
1.1k
Merge trung bình
2 ngày 21 giờ
Pull request đã merge (30 ngày)
27

Mô tả

After the latest release (and possibly the one before - hard to test), a circular dependency error triggers where none did before.

## Steps to reproduce

1. Create 3 models, e.g. User, Participant, Conversation
2. Set up bi-directional HasManyThrough relations (User through Participant to Conversation, Conversation through Participant to User)
3. Use one repository to find instances of the other and include the first, e.g.
`userRepo.conversations(userId).find({include:['users']});`
4. Execute `create`: `userRepo.conversations(userId).create({});`
5. Execute `find` again: `userRepo.conversations(userId).find({include:['users']});`

## Current Behavior

The first execution of `find` succeeds. The second fails with (using Todo <-> Assignment <-> Person from linked branch):
```
Error: Circular dependency detected: repositories.TodoRepository --> @TodoRepository.constructor[2] --> repositories.PersonRepository --> @PersonRepository.constructor[2] --> repositories.TodoRepository
at ResolutionSession.pushBinding (/home/X/project/loopback-next/packages/context/src/resolution-session.ts:228:13)
at Function.runWithBinding (/home/X/project/loopback-next/packages/context/src/resolution-session.ts:107:13)
at Binding.getValue (/home/X/project/loopback-next/packages/context/src/binding.ts:535:40)
at TodoListApplication.getValueOrPromise (/home/X/project/loopback-next/packages/context/src/context.ts:912:32)
at TodoListApplication.get (/home/X/project/loopback-next/packages/context/src/context.ts:712:17)
at getter (/home/X/project/loopback-next/packages/context/src/inject.ts:444:16)
at fetchHasManyThroughModels (/home/X/project/loopback-next/packages/repository/src/relations/has-many/has-many-through.inclusion-resolver.ts:88:30)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at /home/X/project/loopback-next/packages/repository/src/relations/relation.helpers.ts:112:21
at async Promise.all (index 0)
at Object.includeRelatedModels (/home/X/project/loopback-next/packages/repository/src/relations/relation.helpers.ts:120:3)
```

## Expected Behavior

Second execution of `find` on the `HasManyThroughRepositoryFactory` should succeed as well.

## Link to reproduction sandbox

The Todo example at https://github.com/0x0aNL/loopback-next/tree/hmt-circdep-regression is set up with bi-directional HasManyThrough relations: Todo <-> Assignment <-> Person. A test case in `src/__tests__/acceptance/todo.acceptance.ts` executes:
```
await todoRepo.people(1).find({include: ['todos']});
await todoRepo.people(1).create({});
await todoRepo.people(1).find({include: ['todos']});
```

## Additional information

```
> node -e 'console.log(process.platform, process.arch, process.versions.node)'
linux x64 16.1.0
```
```
> npm ls --prod --depth 0 | grep loopback
@loopback/example-todo@3.11.1 /home/X/project/loopback-next/examples/todo
├── @loopback/boot@3.4.1
├── @loopback/core@2.16.1
├── @loopback/repository@3.7.0
├── @loopback/rest-explorer@3.3.1
├── @loopback/rest@9.3.1
├── @loopback/service-proxy@3.2.1
├── loopback-connector-rest@4.0.1
```

It looks as though this regression is introduced between `@loopback/repository@3.5.0 / @loopback/core@2.15.0` and `@loopback/repository@3.6.0 / @loopback/core@2.16.0`.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu với packages/repository/src/relations/has-many/has-many-through.inclusion-resolver.ts và phần tái hiện Todo trong src/__tests__/acceptance/todo.acceptance.ts. So sánh các thay đổi trong repository/core giữa các phiên bản 3.5.0/2.15.0 và 3.6.0/2.16.0, sau đó chạy chuỗi ba bước find/create/find. Hoàn tất khi find được include thứ hai thành công mà không xảy ra lỗi phụ thuộc vòng.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
nodejs, typescript
Lĩnh vực
backend-api-design, databases
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.