Skip to content

[Bug][DAL] Dalgorm.GetPrimaryKeyFields cannot return primarykey of type time.Time #2652

@narrowizard

Description

@narrowizard

Search before asking

  • I had searched in the issues and found no similar issues.

What happened

I want to get primary key of my model, using Dalgorm.GetPrimaryKeyFields method, but it always lost the field of type time.Time.

my model with 3 primary keys

nrzvsyBBbE

only get two string column as primary keys

SToBUOGkd6

What you expected to happen

Dalgorm.GetPrimaryKeyFields should return all primary keys of model.

How to reproduce

  1. Define a model with any field of type time.Time
  2. Set the time.Time field as primary key with gorm tag gorm:"primaryKey"
  3. call Dalgorm.GetPrimaryKeyFields

Anything else

With a deep looking for, GetPrimaryKeyFields will walk all fields for target model with utils.WalkFields. And utils.WalkFields treat time.Time as a struct, so it walks into time.Time. It causes the problem.

https://github.com/apache/incubator-devlake/blob/3a0f52eec956c2bd98ab196335fcfd0ec096cc01/impl/dalgorm/dalgorm.go#L167

Version

main

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Metadata

Metadata

Assignees

Labels

type/bugThis issue is a bug

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions