You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It looks to me that the order in which the dataclass fields are declared is super important.
Example directory structure:
environments
dev
config
servers
server-1
server.yaml
server-2
server.yaml
server-3
server.yaml
Datafile definition:
@datafile("./environments/{self.environment}/config/servers/{self.name}/server.yaml")
class Server:
name: str
environment: str
When running:
import os
from manager.models import Cluster
if __name__ == '__main__':
clusters = list(Server.objects.all())
It ends up raising:
FileNotFoundError: [Errno 2] No such file or directory: '/project/configuration/environments/server-1/config/servers/dev/server.yaml'
This seems to come from when the manager.all method does yield self.get(*values) with values ["server-1", "dev"] which ends up building the path posted above as manager.get iterates on the fields in the order they are declared and sets the values accordingly.
If I declare:
@datafile("./environments/{self.environment}/config/servers/{self.name}/server.yaml")
class Server:
environment: str
name: str
It works.
The text was updated successfully, but these errors were encountered:
devlounge
changed the title
Ordering Issue when trying to retrieve the file with a multi-variables pattern
Fields declaration order really matters when using multi-variables pattern
Jul 16, 2024
There may have been a reason it was implemented this way, but if someone wants to try to convert the parse() results into keyword arguments that may make this more robust:
It looks to me that the order in which the dataclass fields are declared is super important.
Example directory structure:
Datafile definition:
When running:
It ends up raising:
FileNotFoundError: [Errno 2] No such file or directory: '/project/configuration/environments/server-1/config/servers/dev/server.yaml'
This seems to come from when the manager.all method does yield self.get(*values) with values ["server-1", "dev"] which ends up building the path posted above as manager.get iterates on the fields in the order they are declared and sets the values accordingly.
If I declare:
It works.
The text was updated successfully, but these errors were encountered: