update_or_create raising NoMatch()
See original GitHub issueIssue Description
Describe the bug method update_or_create raises NoMatch() instead of creating object
To Reproduce Steps to reproduce the behavior: Models defined as follows
class Movie(ormar.Model):
class Meta(BaseMeta):
tablename = 'movies'
tmdb_id: int = ormar.Integer(nullable=False, primary_key=True)
path: str = ormar.String(max_length=255)
route as follows
@router.post('/radarr')
async def add_movie(movie_to_add: AddMovieSchema):
tmdb_id = movie_to_add.remoteMovie.tmdbId
folder = movie_to_add.movie.folderPath.lstrip('/data/media/movies/merge/')
filename = movie_to_add.movieFile.relativePath
moviepath = os.path.join(folder, filename)
movie = await Movie.objects.update_or_create(tmdb_id=tmdb_id, path=moviepath)
return {}
(Note: this should be a complete and concise piece of code that allows reproduction of an issue)
Expected behavior If the pk tmdb_id exists, it will update the path column If the pk tmdb_id does not exist it will create the row
Screenshots If applicable, add screenshots to help explain your problem.
Versions (please complete the following information):
- Database backend used (mysql/sqlite/postgress) - sqlite
- Python version - 3.9.1
ormar
version - 0.10.14pydantic
version - 1.8.2- if applicable
fastapi
version - 0.66.0
Additional context error traceback
INFO: 127.0.0.1:63368 - "POST /radarr HTTP/1.1" 500 Internal Server Error
ERROR: Exception in ASGI application
Traceback (most recent call last):
File "c:\users\user\appdata\local\programs\python\python39\lib\site-packages\uvicorn\protocols\http\httptools_impl.py", line 371, in run_asgi
result = await app(self.scope, self.receive, self.send)
File "c:\users\user\appdata\local\programs\python\python39\lib\site-packages\uvicorn\middleware\proxy_headers.py", line 59, in __call__
return await self.app(scope, receive, send)
File "c:\users\user\appdata\local\programs\python\python39\lib\site-packages\fastapi\applications.py", line 199, in __call__
await super().__call__(scope, receive, send)
File "c:\users\user\appdata\local\programs\python\python39\lib\site-packages\starlette\applications.py", line 112, in __call__
await self.middleware_stack(scope, receive, send)
File "c:\users\user\appdata\local\programs\python\python39\lib\site-packages\starlette\middleware\errors.py", line 181, in __call__
raise exc from None
File "c:\users\user\appdata\local\programs\python\python39\lib\site-packages\starlette\middleware\errors.py", line 159, in __call__
await self.app(scope, receive, _send)
File "c:\users\user\appdata\local\programs\python\python39\lib\site-packages\starlette\exceptions.py", line 82, in __call__
raise exc from None
File "c:\users\user\appdata\local\programs\python\python39\lib\site-packages\starlette\exceptions.py", line 71, in __call__
await self.app(scope, receive, sender)
File "c:\users\user\appdata\local\programs\python\python39\lib\site-packages\starlette\routing.py", line 580, in __call__
await route.handle(scope, receive, send)
File "c:\users\user\appdata\local\programs\python\python39\lib\site-packages\starlette\routing.py", line 241, in handle
await self.app(scope, receive, send)
File "c:\users\user\appdata\local\programs\python\python39\lib\site-packages\starlette\routing.py", line 52, in app
response = await func(request)
File "c:\users\user\appdata\local\programs\python\python39\lib\site-packages\fastapi\routing.py", line 216, in app
raw_response = await run_endpoint_function(
File "c:\users\user\appdata\local\programs\python\python39\lib\site-packages\fastapi\routing.py", line 149, in run_endpoint_function
return await dependant.call(**values)
File ".\app\routers\api\mediarr.py", line 20, in add_movie
movie = await Movie.objects.update_or_create(tmdb_id=tmdb_id, path=path)
File "c:\users\user\appdata\local\programs\python\python39\lib\site-packages\ormar\queryset\queryset.py", line 987, in update_or_create
model = await self.get(pk=kwargs[pk_name])
File "c:\users\user\appdata\local\programs\python\python39\lib\site-packages\ormar\queryset\queryset.py", line 929, in get
return await self.filter(*args, **kwargs).get()
File "c:\users\user\appdata\local\programs\python\python39\lib\site-packages\ormar\queryset\queryset.py", line 949, in get
self.check_single_result_rows_count(processed_rows)
File "c:\users\user\appdata\local\programs\python\python39\lib\site-packages\ormar\queryset\queryset.py", line 225, in check_single_result_rows_count
raise NoMatch()
ormar.exceptions.NoMatch
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Laravel updateOrCreate with auto-incremental database
My purpose is to update if the value exists, else inserts a new row in the database table after submitting the form. The...
Read more >Update data in database - ormar
update_or_create. update_or_create(**kwargs) -> Model. Updates the model, or in case there is no match in database creates a new one.
Read more >WO2006014439A2 - Hotspot location record database
The information may be extracted by the database to update or create records ... First, they enable scaling with increasing volumes of directory...
Read more >ex_aws_s3/s3.ex at main
raise "not yet implemented". request(:put, bucket, "/"). end. @doc "Update or create a bucket notification configuration".
Read more >GNU gettext utilities
The argument must be non-NULL and have been created through create_foo(). ... Any translation work done seriously will raise many linguistic difficulties, ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@pawamoy - yeah I need to update the docs -> will include this in the next release.
And exactly it has to work this way as otherwise all kwargs would be used to select an object
So it’s actually using all kwargs without the primary key to update the object and determines create/update based on the primary key presence.
Alright thanks!, I’ll close the issue now, Perhaps the documentation can be updated to clarify this a bit.