ubiquity-os-marketplace / text-conversation-rewards

1 stars 27 forks source link

Failed to save permit #152

Closed whilefoo closed 3 weeks ago

whilefoo commented 1 month ago
Failed to create a new location {
  code: '42501',
  details: null,
  hint: null,
  message: 'new row violates row-level security policy for table "locations"'
}
Failed to save permits to the database Error: Failed to retrieve the related location from issue [object Object]
    at PermitGenerationModule._getOrCreateIssueLocation (/home/runner/work/conversation-rewards/conversation-rewards/src/parser/permit-generation-module.ts:248:13)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at PermitGenerationModule._savePermitsToDatabase (/home/runner/work/conversation-rewards/conversation-rewards/src/parser/permit-generation-module.ts:257:28)
    at PermitGenerationModule.transform (/home/runner/work/conversation-rewards/conversation-rewards/src/parser/permit-generation-module.ts:122:9)
    at Processor.run (/home/runner/work/conversation-rewards/conversation-rewards/src/parser/processor.ts:37:24)
    at run (/home/runner/work/conversation-rewards/conversation-rewards/src/run.ts:25:5)

https://github.com/ubiquity-os-marketplace/text-conversation-rewards/actions/runs/11165001249/job/31035657102#step:7:443

0x4007 commented 1 month ago

Locations table is obsolete and was removed

gentlementlegen commented 1 month ago

Locations table was still there to support the part where all the permits are fetched. We could eventually make it a plugin now that we can run actions quickly, that would periodically fetch all the data.

imabutahersiddik commented 1 month ago

/start

imabutahersiddik commented 1 month ago

The error messages you are encountering indicate that there is a problem with row-level security policies in your Supabase database, specifically when trying to insert a new row into the locations table. The error message 'new row violates row-level security policy for table "locations"' suggests that the current user does not have permission to perform the insert operation due to the defined security policies.

Steps to Fix the Bug

  1. Check Row-Level Security Policies:

    • Review the row-level security (RLS) policies for the locations table in your Supabase dashboard. Ensure that the policies allow the user or service account making the request to insert rows into this table.
    • If RLS is enabled, you may need to create a policy that allows inserts for specific roles (e.g., service roles) or conditions.
  2. Modify Insert Logic:

    • If necessary, adjust the logic in your _getOrCreateIssueLocation method to ensure that it handles errors more gracefully. For example, if an insert fails due to permissions, you might want to log a more informative message or handle it differently.
  3. Testing Permissions:

    • Test the permissions of the user or service account that is executing this code. You can do this by running a simple insert command directly in Supabase using SQL, ensuring that it works as expected.
  4. Check User Roles:

    • Ensure that the role used by your application has the necessary permissions to perform both read and write operations on the locations table. This might involve checking your Supabase project's authentication settings and roles.
  5. Error Handling:

    • Improve error handling in your _getOrCreateIssueLocation method to provide more context when an error occurs. This will help you debug similar issues in the future.

Example of Modifying Row-Level Security Policy

Hereโ€™s an example of how you might modify a policy to allow inserts for a specific role:

-- Allow inserts for authenticated users
CREATE POLICY "Allow authenticated inserts"
ON locations
FOR INSERT
TO authenticated
WITH CHECK (true); -- Adjust this condition based on your requirements

Example of Improved Error Handling

You can enhance error handling in your _getOrCreateIssueLocation method like this:

async _getOrCreateIssueLocation(issue: { issueId: number; issueUrl: string }) {
    let locationId: number | null = null;

    const { data: locationData, error: fetchError } = await this._supabase
        .from("locations")
        .select("id")
        .eq("issue_id", issue.issueId)
        .eq("node_url", issue.issueUrl)
        .single();

    if (fetchError) {
        console.error("Error fetching location data:", fetchError);
        throw new Error(`Failed to retrieve location data: ${fetchError.message}`);
    }

    if (!locationData) {
        const issueItem = await getRepo(parseGitHubUrl(issue.issueUrl));
        const { data: newLocationData, error: insertError } = await this._supabase
            .from("locations")
            .insert({
                node_url: issue.issueUrl,
                issue_id: issue.issueId,
                node_type: "Issue",
                repository_id: issueItem.id,
            })
            .select("id")
            .single();

        if (insertError) {
            console.error("Failed to create a new location:", insertError);
            throw new Error(`Failed to create a new location: ${insertError.message}`);
        } else {
            locationId = newLocationData.id;
        }
    } else {
        locationId = locationData.id;
    }

    if (!locationId) {
        throw new Error(`Failed to retrieve the related location from issue ${JSON.stringify(issue)}`);
    }

    return locationId;
}

Conclusion

By reviewing and adjusting your row-level security policies and improving error handling, you should be able to resolve the issues you're facing with creating locations in your database. Make sure to test thoroughly after making these changes!

ubiquity-os-beta[bot] commented 1 month ago
Deadline Mon, Oct 28, 10:57 PM UTC
Beneficiary 0x7245F5Cb278ea948Ab6302Bd911db00Ad4889672

[!TIP]

  • Use /wallet 0x0000...0000 if you want to update your registered payment wallet address.
  • Be sure to open a draft pull request as soon as possible to communicate updates on your progress.
  • Be sure to provide timely updates to us when requested, or you will be automatically unassigned from the task.
ishowvel commented 4 weeks ago

i hope this issues gets fixed asap, this issue has become a blocker for me to qa my pull requests

gentlementlegen commented 4 weeks ago

@ishowvel What do you mean? This issue is not a blocker for a proper run of the plug-in it just outputs an error.

ishowvel commented 4 weeks ago

@ishowvel What do you mean? This issue is not a blocker for a proper run of the plug-in it just outputs an error.

I fixed it after disabling rls for all tables ๐Ÿ˜”

gentlementlegen commented 4 weeks ago

RLS doesn't matter if you use the service key.

ishowvel commented 4 weeks ago

RLS doesn't matter if you use the service key.

Sorry it is my first time using databases in this detail, happy to learn along the way smile ๐Ÿ˜„

ubiquity-os-beta[bot] commented 3 weeks ago

Passed the deadline and no activity is detected, removing assignees: @imabutahersiddik.

gentlementlegen commented 3 weeks ago

Error 42501 indeed means a problem while writing on the table according to postgres. It would mean that there is an RLS issue with the table, probably the key used not having enough privileges. It worked locally fine when I used the service key, maybe the environment value is wrong in this repo? I will check that.

gentlementlegen commented 3 weeks ago

/start

ubiquity-os-beta[bot] commented 3 weeks ago
Deadline Sat, Nov 2, 8:13 AM UTC
Beneficiary 0x0fC1b909ba9265A846b82CF4CE352fc3e7EeB2ED

[!TIP]

  • Use /wallet 0x0000...0000 if you want to update your registered payment wallet address.
  • Be sure to open a draft pull request as soon as possible to communicate updates on your progress.
  • Be sure to provide timely updates to us when requested, or you will be automatically unassigned from the task.
gentlementlegen commented 3 weeks ago

@whilefoo After updating the Supabase key, everything seems to work fine, the permits got saved to the db: image

which corresponds to entries in https://github.com/ubiquity-os-marketplace/daemon-pricing/issues/32#issuecomment-2452913605

So believe this is resolved.

whilefoo commented 3 weeks ago

I guess we can make a new issue for removing location data because it's obsolete like @0x4007 stated

ubiquity-os-beta[bot] commented 3 weeks ago

Passed the deadline and no activity is detected, removing assignees: @gentlementlegen.

gentlementlegen commented 3 weeks ago

@0x4007 I guess this can be closed, not sure if it should be done or not planned.

0x4007 commented 3 weeks ago

Maybe link the correct pull that fixed this and if it's not double dipping rewards then it's valid.

gentlementlegen commented 3 weeks ago

There was no pull fixing it, just investigated and updated the secrets which is why I ask.

ubiquity-os-beta[bot] commented 3 weeks ago

@gentlementlegen the deadline is at Sun, Nov 3, 6:42 AM UTC

ubiquity-os-beta[bot] commented 3 weeks ago

A new workroom has been created for this task. Join chat

ubiquity-os-beta[bot] commented 3 weeks ago

 [ 30 WXDAI ] 

@gentlementlegen
Contributions Overview
ViewContributionCountReward
IssueTask130
IssueComment70
Conversation Incentives
CommentFormattingRelevanceReward
`Locations` table was still there to support the part wh…
0
content:
  content:
    p:
      score: 0
      elementCount: 1
  result: 0
regex:
  wordCount: 35
  wordValue: 0
  result: 0
0.80
@ishowvel What do you mean? This issue is not a blocker for a pr…
0
content:
  content:
    p:
      score: 0
      elementCount: 1
  result: 0
regex:
  wordCount: 24
  wordValue: 0
  result: 0
0.70
RLS doesn't matter if you use the service key.
0
content:
  content:
    p:
      score: 0
      elementCount: 1
  result: 0
regex:
  wordCount: 10
  wordValue: 0
  result: 0
0.90
Error `42501` indeed means a problem while writing on th…
5
content:
  content:
    p:
      score: 0
      elementCount: 1
    a:
      score: 5
      elementCount: 1
  result: 5
regex:
  wordCount: 56
  wordValue: 0
  result: 0
0.950
@whilefoo After updating the Supabase key, everything seems to w…
5
content:
  content:
    p:
      score: 0
      elementCount: 5
    img:
      score: 5
      elementCount: 1
  result: 5
regex:
  wordCount: 40
  wordValue: 0
  result: 0
0.90
@0x4007 I guess this can be closed, not sure if it should be don…
0
content:
  content:
    p:
      score: 0
      elementCount: 1
  result: 0
regex:
  wordCount: 17
  wordValue: 0
  result: 0
0.60
There was no pull fixing it, just investigated and updated the s…
0
content:
  content:
    p:
      score: 0
      elementCount: 1
  result: 0
regex:
  wordCount: 17
  wordValue: 0
  result: 0
0.850

 [ 1.184 WXDAI ] 

@0x4007
Contributions Overview
ViewContributionCountReward
IssueComment21.184
Conversation Incentives
CommentFormattingRelevanceReward
Locations table is obsolete and was removed
0.52
content:
  content:
    p:
      score: 0
      elementCount: 1
  result: 0
regex:
  wordCount: 7
  wordValue: 0.1
  result: 0.52
0.80.416
Maybe link the correct pull that fixed this and if it's not doub…
1.28
content:
  content:
    p:
      score: 0
      elementCount: 1
  result: 0
regex:
  wordCount: 20
  wordValue: 0.1
  result: 1.28
0.60.768

 [ 0.54075 WXDAI ] 

@ishowvel
Contributions Overview
ViewContributionCountReward
IssueComment30.54075
Conversation Incentives
CommentFormattingRelevanceReward
i hope this issues gets fixed asap, this issue has become a bloc…
1.28
content:
  content:
    p:
      score: 0
      elementCount: 1
  result: 0
regex:
  wordCount: 20
  wordValue: 0.1
  result: 1.28
0.70.224
I fixed it after disabling rls for all tables ๐Ÿ˜”
0.65
content:
  content:
    p:
      score: 0
      elementCount: 1
  result: 0
regex:
  wordCount: 9
  wordValue: 0.1
  result: 0.65
0.90.14375
Sorry it is my first time using databases in this detail, happy …
1.17
content:
  content:
    p:
      score: 0
      elementCount: 1
  result: 0
regex:
  wordCount: 18
  wordValue: 0.1
  result: 1.17
0.60.173

 [ 4.367 WXDAI ] 

@whilefoo
Contributions Overview
ViewContributionCountReward
IssueSpecification13.33
IssueComment11.037
Conversation Incentives
CommentFormattingRelevanceReward
```Failed to create a new location {code: '425…
1.11
content:
  content:
    p:
      score: 0
      elementCount: 1
  result: 0
regex:
  wordCount: 17
  wordValue: 0.1
  result: 1.11
13.33
I guess we can make a new issue for removing location data becau…
1.22
content:
  content:
    p:
      score: 0
      elementCount: 1
  result: 0
regex:
  wordCount: 19
  wordValue: 0.1
  result: 1.22
0.851.037