GlobalDataStore:ListKeysAsync() does not function properly when scopes are used

Reproduction Steps
Currently, if you call GlobalDataStore:ListKeysAsync() from the new datastore features on a datastore that was fetched with a scope, the API does not function as expected, it fails to return keys that exist.

Reproduction steps:

  1. Have a datastore with the following structure:
Key Name Key Value
etc etc
4 {Data}
3 {Data}
2 {Data}
1 {Data}
  1. List the keys in the datastore with a scope, e.g. the player’s user ID as the scope:
local DatastoreService = game:GetService("DataStoreService")

local DatastoreOptions = Instance.new('DataStoreOptions')
DatastoreOptions:SetExperimentalFeatures({
	v2 = true
})
local Datastore = DatastoreService:GetDataStore("PreAlpha_PlayerData1_Data","73223877",DatastoreOptions)
local KeyPages = Datastore:ListKeysAsync("",10)
local CurrentKeyPage = KeyPages:GetCurrentPage()

for Index,DatastoreKey in pairs(CurrentKeyPage) do
	print(Index,DatastoreKey.KeyName)
end

Notice that only certain keys are displayed, and the rest are not:
image

  1. Try displaying a specific key with ListKeysAsync :
local DatastoreService = game:GetService("DataStoreService")

local DatastoreOptions = Instance.new('DataStoreOptions')
DatastoreOptions:SetExperimentalFeatures({
	v2 = true
})
local Datastore = DatastoreService:GetDataStore("PreAlpha_PlayerData1_Data","73223877",DatastoreOptions)
local KeyPages = Datastore:ListKeysAsync("36",10)
local CurrentKeyPage = KeyPages:GetCurrentPage()

for Index,DatastoreKey in pairs(CurrentKeyPage) do
	print(Index,DatastoreKey.KeyName)
end

Notice that some keys which were not displaying properly before are now being displayed:
image

  1. Enable AllScopes. Notice that all keys properly display.
local DatastoreService = game:GetService("DataStoreService")

local DatastoreOptions = Instance.new('DataStoreOptions')
DatastoreOptions:SetExperimentalFeatures({
	v2 = true
})
DatastoreOptions.AllScopes = true
local Datastore = DatastoreService:GetDataStore("PreAlpha_PlayerData1_Data","",DatastoreOptions)
local KeyPages = Datastore:ListKeysAsync("",10)
local CurrentKeyPage = KeyPages:GetCurrentPage()

for Index,DatastoreKey in pairs(CurrentKeyPage) do
	print(Index,DatastoreKey.KeyName)
end

image

Expected Behavior
It is expected that calling ListKeysAsync() would list all available keys in a datastore, regardless of whether or not a datastore was fetched using a scope. If a scope was used, expected behavior is that only keys under that scope are included.

Actual Behavior
Only certain keys from a scope’d datastore are displayed. Specifically searching for keys that were omitted with the prefix filter makes the keys get displayed, otherwise they are not displayed from ListKeysAsync().

Workaround
None

Issue Area: Engine
Issue Type: Other
Impact: High
Frequency: Constantly
Date First Experienced: 2021-08-12 07:08:00 (-04:00)

7 Likes

Sorry about the late reply. The code does not iterate through all the pages. Can you try iterating through all pages and see whether it returns all the keys ?

3 Likes

Hi, sorry for the late reply! Discourse decided to not notify me of your reply.
Will give this a try tomorrow. :slight_smile:

Hi, I gave it a try and it seems to work properly now!
The issue wasn’t that the code wasn’t iterating through the keys, the API simply wasn’t returning all of the available keys when this bug report was filed. Seems to work now however, as seen below:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.