pubkey / pubkey/rxdb

Bug: Array fields are not supported in Supabase replication (push fails with "unknown how to handle type: object")

Open
#8,473 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

stale
Dominant language
TypeScript
Stars
23.4k
Forks
1.2k
Avg merge
1d 4h
Merged PRs (30d)
110

Description

Description

When using Supabase replication, documents containing array fields (e.g. string[]) cause the push process to fail with the following error:

Error: unknown how to handle type: object

This issue occurs during update (patch) and delete operations, while insert operations work correctly.


Steps to reproduce
  1. Define a schema with an array field:
{
	"title": "hero schema",
	"version": 0,
	"primaryKey": "name",
	"type": "object",
	"properties": {
		"name": {
			"type": "string",
			"maxLength": 100
		},
		"skills": {
			"type": "array",
			items: { type: "string" }
		}
	}
}
  1. Insert a document:
await collection.insert({
  name: "Foo",
  skills: ["Teaching", "Summarizing"],
});
  1. Run replication

  2. Delete the document:

await doc.remove();
  1. Trigger replication

Location of the Issue

The issue appears to originate from the addDocEqualityToQuery function, where document fields are converted into query filters.

export function addDocEqualityToQuery<RxDocType>(
    jsonSchema: RxJsonSchema<RxDocumentData<RxDocType>>,
    deletedField: string,
    modifiedField: string,
    doc: WithDeleted<RxDocType>,
    query: any
) {
	// ....
	
	for (const key of Object.keys(doc)) {
        if (ignoreKeys.has(key)) {
            continue;
        }

        const v = (doc as any)[key];
        const type = typeof v;

        if (type === "string" || type === "number") {
            query = query.eq(key, v);
        } else if (type === "boolean" || v === null) {
            query = query.is(key, v);
        } else if (type === 'undefined') {
            query = query.is(key, null);
        } else {
            // Problem: arrays and JSON objects are not handled
            throw new Error(`unknown how to handle type: ${type}`)
        }
    }
    
    //...
}

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the addDocEqualityToQuery function identified in the issue and trace how it builds filters for Supabase replication during update and delete operations. Reproduce the schema and document example, then verify that documents with array fields can be updated and deleted through replication without the unknown type error.

Written by the indexing model from the issue text.

Assessment

Tech stack
supabase, typescript
Domain
databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
70/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.