question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Relations fail with "field 'task.project' cannot be accessed for POST"

See original GitHub issue

Hi, didn’t have to say it yet, but thanks for this great library 👍

I’m trying to map relationships to a classes already mapped to Objectify using the standard @JsonApiRelation and @JsonApiRelationId annotations, but for an unknown reason, I get this kind of message as soon as I try to run some commands (be it POST, PATCH or DELETE) :

{
  "errors": [
    {
      "status": "403",
      "title": "FORBIDDEN",
      "detail": "field 'task.project' cannot be accessed for POST"
    }
  ]
}

I’m well aware that they’d rather be splitted into model and viewmodel classes, but that’s what I have for now (and that’s beyond the point I guess).

Here is a code sample (greatly inspired from the examples in the doc) :

@JsonApiResource(type = "task")
@Entity
public class Task {
    @JsonApiId
    @Id
    private String id;

    private Ref<Project> project;

    @JsonApiRelationId
    private String projectId;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    @JsonApiRelation
    public Project getProject() {
        return project != null ? project.get() : null;
    }

    @JsonApiRelation
    public void setProject(Project project) {
        this.project = project != null ? Ref.create(project) : null;
        this.projectId = projectId != null ? project.getId() : null;
    }

    public String getProjectId() {
        return projectId;
    }

    public void setProjectId(String projectId) {
        this.projectId = projectId;
        this.project = null;
    }
}

@JsonApiResource(type = "project")
@Entity
public class Project {
    @JsonApiId
    @Id
    private String id;

    private Set<Ref<Task>> tasks;

    @JsonApiRelationId
    private Set<String> taskIds;

    public Project() {
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    @JsonApiRelation(mappedBy = "project")
    public Set<Task> getTasks() {
        return tasks == null ? null :
                tasks.stream()
                        .map(Ref::get)
                        .collect(toSet());
    }

    @JsonApiRelation(mappedBy = "project")
    public void setTasks(Set<Task> tasks) {
        this.tasks = tasks == null ? null :
                tasks.stream()
                        .map(Ref::create)
                        .collect(toSet());
    }

    public Set<String> getTaskIds() {
        return taskIds;
    }

    public void setTaskIds(Set<String> tasksId) {
        this.taskIds = tasksId;
        this.tasks = null;
    }
}

There is a resource repo for those classes as well (it’s longer, but let me know if you need it), extending ResourceRepositoryBase and overriding all the CRUD methods (which works well), but no relationship repo, as I read in the doc that for this kind of standard use case they were not necessary.

Am I missing something obvious here ? Should I write relationships repos anyway ?

Thanks!

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
remmeiercommented, Jul 31, 2019

I guess it would be good to have a closer look at the BeanInformation class. It can access field for historic reasons, maybe it should not do that anymore. just rely on getter/setter

0reactions
DeafLightcommented, Jul 31, 2019

I’ll let you decide whether this issue should be closed or not then 😇

Read more comments on GitHub >

github_iconTop Results From Across the Web

Circular Relationship Error when indenting Task - Office
Fixes an error that occurs when you indent tasks that are linked in a predecessor or successor relationship.
Read more >
(fields.E300) Field defines a relation with model which is ...
E300) Field defines a relation with model 'Godzina', which is either not installed, or is abstract. What does it mean? I would like...
Read more >
MS Project 101 - Add Task Relationships - FS/FF/SS/SF
Learn how to add relationship types to your task predecessors and successors in MS Project. You will learn different techniques to add ...
Read more >
Project Fields not viewable - Tips and Tricks
We add different members (hiring managers) to each task (some of which we have to invite to asana if they aren't in already)...
Read more >
Project settings - GitLab Docs
If you disable Repository, project users cannot access: Merge requests; CI/CD ... Configure Error Tracking to discover and view Sentry errors within GitLab....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found