`type::thing` Casts UUIDs To Strings Making Certain Queries Impossible

by ADMIN 71 views

Introduction

SurrealDB is a powerful, open-source, document-graph database that provides a flexible and scalable solution for storing and querying data. However, like any complex system, it is not immune to bugs and issues. In this article, we will explore a specific problem that arises when using the type::thing command in SurrealDB, which casts UUIDs to strings, making certain queries impossible.

What Component Does This Affect?

The type::thing command is a part of the SurrealDB Server component. This command is used to create a new type of thing, which is a document that can be used to store data.

Describe the Bug

The bug arises when creating a new type of thing using the type::thing command. When a UUID is used as the id for the thing, it is cast to a string, resulting in two different records being created: one with a UUID id and one with a string id.

CREATE person:u"d1c22eef-6713-4808-9936-15b8313c7d88";

CREATE type::thing("person", "d1c22eef-6713-4808-9936-15b8313c7d88");

This will produce two different records, one with a UUID id, and one with a string id:

-------- Query 1 (1ms) --------

[
	{
		id: person:u'd1c22eef-6713-4808-9936-15b8313c7d88'
	}
]

-------- Query 2 (0ns) --------

[
	{
		id: person:⟨d1c22eef-6713-4808-9936-15b8313c7d88⟩
	}
]

This also means that it's impossible to perform binding queries like:

SELECT * FROM type::thing("person", <uuid> $person_id);

Because it will always treat the id as a string, rather than a UUID.

Steps to Reproduce

To reproduce this issue, follow these steps:

  1. Run the following query:
CREATE person:u"d1c22eef-6713-4808-9936-15b8313c7d88";

CREATE type::thing("person", "d1c22eef-6713-4808-9936-15b8313c7d88");

Expected Behaviour

The expected behaviour is that type::thing should not be casting everything into strings. This would allow for binding queries to work correctly, and would prevent the creation of two different records with different id types.

SurrealDB Version

The SurrealDB version used to reproduce this issue is 2.2.1 for Linux on x86_64.

Contact Details

No response was received from the SurrealDB team regarding this issue.

Is This a Bug with SurrealDB?

Yes, this is a bug with SurrealDB, not with the application using it. The issue arises from the way the type::thing command handles UUIDs, and is not a problem with the application code.

Is There an Existing Issue for This?

Yes, this issue has been searched for in the existing issues, and no similar issue was found.

Code of Conduct

Yes, the author agrees to follow this project's Code of Conduct.

Conclusion

Q: What is the UUID casting issue in SurrealDB Server?

A: The UUID casting issue in SurrealDB Server is a problem that arises when using the type::thing command. When a UUID is used as the id for the thing, it is cast to a string, resulting in two different records being created: one with a UUID id and one with a string id.

Q: What are the consequences of this issue?

A: The consequences of this issue are that it makes certain queries impossible. For example, binding queries like SELECT * FROM type::thing("person", <uuid> $person_id); will not work correctly because the id will be treated as a string, rather than a UUID.

Q: How can I reproduce this issue?

A: To reproduce this issue, follow these steps:

  1. Run the following query:
CREATE person:u"d1c22eef-6713-4808-9936-15b8313c7d88";

CREATE type::thing("person", "d1c22eef-6713-4808-9936-15b8313c7d88");

Q: What is the expected behaviour?

A: The expected behaviour is that type::thing should not be casting everything into strings. This would allow for binding queries to work correctly, and would prevent the creation of two different records with different id types.

Q: Is this a bug with SurrealDB?

A: Yes, this is a bug with SurrealDB, not with the application using it. The issue arises from the way the type::thing command handles UUIDs, and is not a problem with the application code.

Q: Is there an existing issue for this?

A: Yes, this issue has been searched for in the existing issues, and no similar issue was found.

Q: What SurrealDB version is affected by this issue?

A: The SurrealDB version used to reproduce this issue is 2.2.1 for Linux on x86_64.

Q: How can I fix this issue?

A: To fix this issue, the type::thing command should be modified to handle UUIDs correctly, and not cast them to strings. This would allow for binding queries to work correctly, and would prevent the creation of two different records with different id types.

Q: What is the impact of this issue on my application?

A: The impact of this issue on your application will depend on how you are using the type::thing command and how you are handling UUIDs in your application. If you are using binding queries, this issue will prevent them from working correctly. If you are not using binding queries, this issue may not have a significant impact on your application.

Q: Can I work around this issue?

A: Yes, you can work around this issue by modifying your application to handle the UUID casting issue. For example, you can use a different command to create the thing, or you can modify your application to handle the string id correctly.

Q: How can I report this issue to SurrealDB?

A: To report this issue to SurrealDB, you can follow these steps:

  1. Go to the SurrealDB issue tracker.
  2. Click on the "New Issue" button.
  3. Fill in the issue details, including the steps to reproduce the issue and the expected behaviour.
  4. Click on the "Submit" button.

By following these steps, you can report this issue to SurrealDB and help to resolve the UUID casting issue.