[almighty] Potential cyclic import issue in core.

Konrad Kleine kkleine at redhat.com
Mon Oct 10 08:07:00 UTC 2016


Pranav,

If it really is the simplest solution, I would suggest that you move the
LifeCycle into github.com/almighty/almighty-core/models/lifecycle package
if the struct is only used within the models package.

Regards,
Konrad

On Sat, Oct 8, 2016 at 5:25 AM, Pranav Gore <pgore at redhat.com> wrote:

> ​Hi Team Core,
>
> *Context/Background:-*
> I am working on #244
> <https://github.com/almighty/almighty-core/issues/244>. The task is to do
> `fields["system.creator"]=currentLoggedInUser`.
>
> There, I want to call a method Locate from package "Token" which returns
> current logged in user.
> While doing so I am facing cyclic import problem.
>
> *Reason:-* Work_item_repo is in package "models", it wants to call Locate
> method from package "token".
> But "token" pachakge imports "account" package and "account" package
> imports "models".
> Hence "models" package is unable to import "token" => cyclic dependency.
>
> *Debugging:-* When I was looking into "account" package, what exactly it
> needs from "models" package is ONLY "models.LifeCycle" and nothing else as
> of now.
>
> *Solutions:-* One quick possible/feasible solution is to put
> models.LifeCycle into different new package of its own, refactor and move
> on (IMO we should do this as first step).
>
> Another is to write a middleware(as mentioned in #244
> <https://github.com/almighty/almighty-core/issues/244>) for injecting
> loggedInUser which will be in package "middleware" and avoid cyclic import,
>
> Or redesigning to decouple models package into smaller chunks ?
>
> PFA- I have attached output of `go list -f` on account, models, token
> packages.
>
> Any input on this will be helpful :)
>
>
> Thanks,
> Pranav
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/almighty-public/attachments/20161010/f5bd7943/attachment.htm>


More information about the almighty-public mailing list