Commit 51db0542 authored by arjun.b's avatar arjun.b

17 may commit

parent 25493b85
...@@ -7,8 +7,6 @@ L ...@@ -7,8 +7,6 @@ L
scripts/utils/mongo_utils.py,0\2\028245be183e97120b9832f8912cad7b0f292d72 scripts/utils/mongo_utils.py,0\2\028245be183e97120b9832f8912cad7b0f292d72
7 7
main.py,f\1\f1bdda93d9a278e358509d498e17d97764c1fb29 main.py,f\1\f1bdda93d9a278e358509d498e17d97764c1fb29
6
app.py,1\3\13cce7fd076299c81b4986166f3d822791c9490e
: :
Dockerfile,6\6\6651ddff6eb82c840ced7c1dddee15c6e1913dd4 Dockerfile,6\6\6651ddff6eb82c840ced7c1dddee15c6e1913dd4
...@@ -16,7 +14,7 @@ Dockerfile,6\6\6651ddff6eb82c840ced7c1dddee15c6e1913dd4 ...@@ -16,7 +14,7 @@ Dockerfile,6\6\6651ddff6eb82c840ced7c1dddee15c6e1913dd4
update_db.py,b\e\bed2b5a444c481de1fb8954f4017582ec23f989e update_db.py,b\e\bed2b5a444c481de1fb8954f4017582ec23f989e
? ?
requirments.txt,6\3\63ca6d3cb5645a462d48767fff3c8b7de2fad47f requirments.txt,6\3\63ca6d3cb5645a462d48767fff3c8b7de2fad47f
n b
>scripts/database/mongodb/asset_manager/collections/__init__.py,8\5\85662d542fe3a35fddc27f559d6e72183c0c7c60 2scripts/database/mongodb/asset_manager/__init__.py,d\2\d2443db26301eb4305c1a214cc05c5dd30a84918
I T
scripts/logging/logger.py,2\a\2a7cfbe29f4cfc67ff2d5340ee99290abe2b82f7 $scripts/database/mongodb/__init__.py,9\c\9c64991521effa9b1b4f0ff07644b9b658515308
\ No newline at end of file \ No newline at end of file
__version__ = "2.0"
\ No newline at end of file
import __version__
__author__ = 'INT- 714: Arjun B'
__version__ = __version__.__version__
__date__ = '15 May 2023'
import uvicorn import uvicorn
from scripts.config import Services from scripts.config import Services
import argparse
from scripts.logging.logger import logger from scripts.logging.logger import logger
# starting the application
ap = argparse.ArgumentParser()
if __name__ == "__main__": if __name__ == "__main__":
try: try:
uvicorn.run("main:app", host=Services.HOST, port=Services.PORT) logger.info(f"****Starting {Services.PROJECT_NAME} v.{__version__}***")
print(f"****************************Starting {Services.PROJECT_NAME} {__version__}****************************")
# creating the argument for the port
ap.add_argument(
"--port",
"-p",
required=False,
default=Services.PORT,
help="Port to start the application.",
)
# creating the argument for the host
ap.add_argument(
"--bind",
"-b",
required=False,
default=Services.HOST,
help="IF to start the application.",
)
ap.add_argument(
"--workers",
"-w",
type=int,
default=Services.WORKERS,
help="Number of worker processes to use.",
)
arguments = vars(ap.parse_args())
# logging the info
logger.info(f"App Starting at {arguments['bind']}:{arguments['port']} with {arguments['workers']} workers.")
uvicorn.run(
"main:app",
host=arguments["bind"],
port=int(arguments["port"]),
workers=arguments["workers"]
)
except Exception as e: except Exception as e:
logger.error(f"error from app {e}") logger.exception(f'Services Failed with error from app {e}')
...@@ -201,3 +201,301 @@ bson.errors.InvalidDocument: cannot encode object: TestUpdate(mac='string', coun ...@@ -201,3 +201,301 @@ bson.errors.InvalidDocument: cannot encode object: TestUpdate(mac='string', coun
2023-05-15 10:55:37 - INFO - [MainThread:create_tag(): 11] - create tags called 2023-05-15 10:55:37 - INFO - [MainThread:create_tag(): 11] - create tags called
2023-05-15 10:55:37 - INFO - [MainThread:update_name(): 24] - Update name method called 2023-05-15 10:55:37 - INFO - [MainThread:update_name(): 24] - Update name method called
2023-05-15 10:55:37 - INFO - [MainThread:create_tag(): 22] - database updated 2023-05-15 10:55:37 - INFO - [MainThread:create_tag(): 22] - database updated
2023-05-16 13:01:49 - ERROR - [MainThread:<module>(): 10] - error from app cannot import name 'TestUpdate' from 'scripts.schemas.tag_schema' (E:\Asset Manager V2\scripts\schemas\tag_schema.py)
2023-05-16 13:02:00 - ERROR - [MainThread:<module>(): 10] - error from app cannot import name 'TestUpdate' from 'scripts.schemas.tag_schema' (E:\Asset Manager V2\scripts\schemas\tag_schema.py)
2023-05-16 13:02:13 - ERROR - [MainThread:<module>(): 10] - error from app cannot import name 'TestUpdate' from 'scripts.schemas.tag_schema' (E:\Asset Manager V2\scripts\schemas\tag_schema.py)
2023-05-16 13:03:35 - INFO - [MainThread:tag_creation(): 41] - creating new tag api called
2023-05-16 13:03:35 - INFO - [MainThread:tag_details(): 34] - new tag created.....
2023-05-16 13:03:35 - INFO - [MainThread:create_tag(): 37] - creating new tag
2023-05-16 13:03:35 - INFO - [MainThread:tag_details(): 47] - new tag created
2023-05-16 15:10:16 - INFO - [MainThread:tag_creation(): 53] - creating new tag api called
2023-05-16 15:10:16 - INFO - [MainThread:tag_details(): 34] - new tag created.....
2023-05-16 15:10:16 - INFO - [MainThread:create_tag(): 37] - creating new tag
2023-05-16 15:10:16 - INFO - [MainThread:tag_details(): 47] - new tag created
2023-05-16 16:27:25 - INFO - [MainThread:tag_creation(): 52] - creating new tag api called
2023-05-16 16:27:25 - INFO - [MainThread:tag_details(): 34] - new tag created.....
2023-05-16 16:27:25 - INFO - [MainThread:create_tag(): 37] - creating new tag
2023-05-16 16:27:25 - ERROR - [MainThread:update_one(): 147] - Cannot create field 'country' in element {tags: [ "" ]}, full error: {'index': 0, 'code': 28, 'errmsg': 'Cannot create field \'country\' in element {tags: [ "" ]}'}
Traceback (most recent call last):
File "E:\Asset Manager V2\scripts\utils\mongo_tools\mongo_sync.py", line 145, in update_one
return collection.update_one(query, {strategy: data}, upsert=upsert)
File "E:\Anaconda\lib\site-packages\pymongo\collection.py", line 1028, in update_one
self._update_retryable(
File "E:\Anaconda\lib\site-packages\pymongo\collection.py", line 877, in _update_retryable
return self.__database.client._retryable_write(
File "E:\Anaconda\lib\site-packages\pymongo\mongo_client.py", line 1552, in _retryable_write
return self._retry_with_session(retryable, func, s, None)
File "E:\Anaconda\lib\site-packages\pymongo\mongo_client.py", line 1438, in _retry_with_session
return self._retry_internal(retryable, func, session, bulk)
File "E:\Anaconda\lib\site-packages\pymongo\mongo_client.py", line 1470, in _retry_internal
return func(session, sock_info, retryable)
File "E:\Anaconda\lib\site-packages\pymongo\collection.py", line 869, in _update
return self._update(
File "E:\Anaconda\lib\site-packages\pymongo\collection.py", line 846, in _update
_check_write_command_response(result)
File "E:\Anaconda\lib\site-packages\pymongo\helpers.py", line 229, in _check_write_command_response
_raise_last_write_error(write_errors)
File "E:\Anaconda\lib\site-packages\pymongo\helpers.py", line 211, in _raise_last_write_error
raise WriteError(error.get("errmsg"), error.get("code"), error)
pymongo.errors.WriteError: Cannot create field 'country' in element {tags: [ "" ]}, full error: {'index': 0, 'code': 28, 'errmsg': 'Cannot create field \'country\' in element {tags: [ "" ]}'}
2023-05-16 16:27:25 - ERROR - [MainThread:create_tag(): 43] - error from creating new tag Cannot create field 'country' in element {tags: [ "" ]}, full error: {'index': 0, 'code': 28, 'errmsg': 'Cannot create field \'country\' in element {tags: [ "" ]}'}
2023-05-16 16:28:21 - INFO - [MainThread:tag_creation(): 52] - creating new tag api called
2023-05-16 16:28:21 - INFO - [MainThread:tag_details(): 34] - new tag created.....
2023-05-16 16:28:21 - INFO - [MainThread:create_tag(): 37] - creating new tag
2023-05-16 16:28:21 - ERROR - [MainThread:update_one(): 147] - Cannot create field 'country' in element {tags: [ "" ]}, full error: {'index': 0, 'code': 28, 'errmsg': 'Cannot create field \'country\' in element {tags: [ "" ]}'}
Traceback (most recent call last):
File "E:\Asset Manager V2\scripts\utils\mongo_tools\mongo_sync.py", line 145, in update_one
return collection.update_one(query, {strategy: data}, upsert=upsert)
File "E:\Anaconda\lib\site-packages\pymongo\collection.py", line 1028, in update_one
self._update_retryable(
File "E:\Anaconda\lib\site-packages\pymongo\collection.py", line 877, in _update_retryable
return self.__database.client._retryable_write(
File "E:\Anaconda\lib\site-packages\pymongo\mongo_client.py", line 1552, in _retryable_write
return self._retry_with_session(retryable, func, s, None)
File "E:\Anaconda\lib\site-packages\pymongo\mongo_client.py", line 1438, in _retry_with_session
return self._retry_internal(retryable, func, session, bulk)
File "E:\Anaconda\lib\site-packages\pymongo\mongo_client.py", line 1470, in _retry_internal
return func(session, sock_info, retryable)
File "E:\Anaconda\lib\site-packages\pymongo\collection.py", line 869, in _update
return self._update(
File "E:\Anaconda\lib\site-packages\pymongo\collection.py", line 846, in _update
_check_write_command_response(result)
File "E:\Anaconda\lib\site-packages\pymongo\helpers.py", line 229, in _check_write_command_response
_raise_last_write_error(write_errors)
File "E:\Anaconda\lib\site-packages\pymongo\helpers.py", line 211, in _raise_last_write_error
raise WriteError(error.get("errmsg"), error.get("code"), error)
pymongo.errors.WriteError: Cannot create field 'country' in element {tags: [ "" ]}, full error: {'index': 0, 'code': 28, 'errmsg': 'Cannot create field \'country\' in element {tags: [ "" ]}'}
2023-05-16 16:28:21 - ERROR - [MainThread:create_tag(): 43] - error from creating new tag Cannot create field 'country' in element {tags: [ "" ]}, full error: {'index': 0, 'code': 28, 'errmsg': 'Cannot create field \'country\' in element {tags: [ "" ]}'}
2023-05-16 16:35:34 - INFO - [MainThread:tag_creation(): 52] - creating new tag api called
2023-05-16 16:35:34 - INFO - [MainThread:tag_details(): 34] - new tag created.....
2023-05-16 16:35:34 - INFO - [MainThread:create_tag(): 37] - creating new tag
2023-05-16 16:35:35 - ERROR - [MainThread:update_one(): 147] - upsert must be True or False
Traceback (most recent call last):
File "E:\Asset Manager V2\scripts\utils\mongo_tools\mongo_sync.py", line 145, in update_one
return collection.update_one(query, {strategy: data}, upsert=upsert)
File "E:\Anaconda\lib\site-packages\pymongo\collection.py", line 1028, in update_one
self._update_retryable(
File "E:\Anaconda\lib\site-packages\pymongo\collection.py", line 877, in _update_retryable
return self.__database.client._retryable_write(
File "E:\Anaconda\lib\site-packages\pymongo\mongo_client.py", line 1552, in _retryable_write
return self._retry_with_session(retryable, func, s, None)
File "E:\Anaconda\lib\site-packages\pymongo\mongo_client.py", line 1438, in _retry_with_session
return self._retry_internal(retryable, func, session, bulk)
File "E:\Anaconda\lib\site-packages\pymongo\mongo_client.py", line 1470, in _retry_internal
return func(session, sock_info, retryable)
File "E:\Anaconda\lib\site-packages\pymongo\collection.py", line 869, in _update
return self._update(
File "E:\Anaconda\lib\site-packages\pymongo\collection.py", line 779, in _update
common.validate_boolean("upsert", upsert)
File "E:\Anaconda\lib\site-packages\pymongo\common.py", line 164, in validate_boolean
raise TypeError("%s must be True or False" % (option,))
TypeError: upsert must be True or False
2023-05-16 16:35:35 - ERROR - [MainThread:create_tag(): 43] - error from creating new tag upsert must be True or False
2023-05-16 16:48:12 - INFO - [MainThread:tag_creation(): 52] - creating new tag api called
2023-05-16 16:48:12 - INFO - [MainThread:tag_details(): 34] - new tag created.....
2023-05-16 16:48:12 - INFO - [MainThread:create_tag(): 37] - creating new tag
2023-05-16 16:48:12 - ERROR - [MainThread:update_one(): 147] - The dollar ($) prefixed field '$push' in '$push' is not allowed in the context of an update's replacement document. Consider using an aggregation pipeline with $replaceWith., full error: {'index': 0, 'code': 52, 'errmsg': "The dollar ($) prefixed field '$push' in '$push' is not allowed in the context of an update's replacement document. Consider using an aggregation pipeline with $replaceWith."}
Traceback (most recent call last):
File "E:\Asset Manager V2\scripts\utils\mongo_tools\mongo_sync.py", line 145, in update_one
return collection.update_one(query, {strategy: data}, upsert=upsert)
File "E:\Anaconda\lib\site-packages\pymongo\collection.py", line 1028, in update_one
self._update_retryable(
File "E:\Anaconda\lib\site-packages\pymongo\collection.py", line 877, in _update_retryable
return self.__database.client._retryable_write(
File "E:\Anaconda\lib\site-packages\pymongo\mongo_client.py", line 1552, in _retryable_write
return self._retry_with_session(retryable, func, s, None)
File "E:\Anaconda\lib\site-packages\pymongo\mongo_client.py", line 1438, in _retry_with_session
return self._retry_internal(retryable, func, session, bulk)
File "E:\Anaconda\lib\site-packages\pymongo\mongo_client.py", line 1470, in _retry_internal
return func(session, sock_info, retryable)
File "E:\Anaconda\lib\site-packages\pymongo\collection.py", line 869, in _update
return self._update(
File "E:\Anaconda\lib\site-packages\pymongo\collection.py", line 846, in _update
_check_write_command_response(result)
File "E:\Anaconda\lib\site-packages\pymongo\helpers.py", line 229, in _check_write_command_response
_raise_last_write_error(write_errors)
File "E:\Anaconda\lib\site-packages\pymongo\helpers.py", line 211, in _raise_last_write_error
raise WriteError(error.get("errmsg"), error.get("code"), error)
pymongo.errors.WriteError: The dollar ($) prefixed field '$push' in '$push' is not allowed in the context of an update's replacement document. Consider using an aggregation pipeline with $replaceWith., full error: {'index': 0, 'code': 52, 'errmsg': "The dollar ($) prefixed field '$push' in '$push' is not allowed in the context of an update's replacement document. Consider using an aggregation pipeline with $replaceWith."}
2023-05-16 16:48:12 - ERROR - [MainThread:create_tag(): 43] - error from creating new tag The dollar ($) prefixed field '$push' in '$push' is not allowed in the context of an update's replacement document. Consider using an aggregation pipeline with $replaceWith., full error: {'index': 0, 'code': 52, 'errmsg': "The dollar ($) prefixed field '$push' in '$push' is not allowed in the context of an update's replacement document. Consider using an aggregation pipeline with $replaceWith."}
2023-05-16 16:53:22 - INFO - [MainThread:tag_creation(): 52] - creating new tag api called
2023-05-16 16:53:22 - INFO - [MainThread:tag_details(): 34] - new tag created.....
2023-05-16 16:53:22 - INFO - [MainThread:create_tag(): 37] - creating new tag
2023-05-16 16:53:22 - ERROR - [MainThread:update_one(): 147] - The field 'customer' must be an array but is of type string in document {_id: ObjectId('645cf178f74445e7eff0458b')}, full error: {'index': 0, 'code': 2, 'errmsg': "The field 'customer' must be an array but is of type string in document {_id: ObjectId('645cf178f74445e7eff0458b')}"}
Traceback (most recent call last):
File "E:\Asset Manager V2\scripts\utils\mongo_tools\mongo_sync.py", line 145, in update_one
return collection.update_one(query, {strategy: data}, upsert=upsert)
File "E:\Anaconda\lib\site-packages\pymongo\collection.py", line 1028, in update_one
self._update_retryable(
File "E:\Anaconda\lib\site-packages\pymongo\collection.py", line 877, in _update_retryable
return self.__database.client._retryable_write(
File "E:\Anaconda\lib\site-packages\pymongo\mongo_client.py", line 1552, in _retryable_write
return self._retry_with_session(retryable, func, s, None)
File "E:\Anaconda\lib\site-packages\pymongo\mongo_client.py", line 1438, in _retry_with_session
return self._retry_internal(retryable, func, session, bulk)
File "E:\Anaconda\lib\site-packages\pymongo\mongo_client.py", line 1470, in _retry_internal
return func(session, sock_info, retryable)
File "E:\Anaconda\lib\site-packages\pymongo\collection.py", line 869, in _update
return self._update(
File "E:\Anaconda\lib\site-packages\pymongo\collection.py", line 846, in _update
_check_write_command_response(result)
File "E:\Anaconda\lib\site-packages\pymongo\helpers.py", line 229, in _check_write_command_response
_raise_last_write_error(write_errors)
File "E:\Anaconda\lib\site-packages\pymongo\helpers.py", line 211, in _raise_last_write_error
raise WriteError(error.get("errmsg"), error.get("code"), error)
pymongo.errors.WriteError: The field 'customer' must be an array but is of type string in document {_id: ObjectId('645cf178f74445e7eff0458b')}, full error: {'index': 0, 'code': 2, 'errmsg': "The field 'customer' must be an array but is of type string in document {_id: ObjectId('645cf178f74445e7eff0458b')}"}
2023-05-16 16:53:22 - ERROR - [MainThread:create_tag(): 43] - error from creating new tag The field 'customer' must be an array but is of type string in document {_id: ObjectId('645cf178f74445e7eff0458b')}, full error: {'index': 0, 'code': 2, 'errmsg': "The field 'customer' must be an array but is of type string in document {_id: ObjectId('645cf178f74445e7eff0458b')}"}
2023-05-16 16:54:46 - INFO - [MainThread:tag_creation(): 52] - creating new tag api called
2023-05-16 16:54:46 - INFO - [MainThread:tag_details(): 34] - new tag created.....
2023-05-16 16:54:46 - INFO - [MainThread:create_tag(): 37] - creating new tag
2023-05-16 16:54:46 - ERROR - [MainThread:update_one(): 147] - The field 'customer' must be an array but is of type string in document {_id: ObjectId('645cf178f74445e7eff0458b')}, full error: {'index': 0, 'code': 2, 'errmsg': "The field 'customer' must be an array but is of type string in document {_id: ObjectId('645cf178f74445e7eff0458b')}"}
Traceback (most recent call last):
File "E:\Asset Manager V2\scripts\utils\mongo_tools\mongo_sync.py", line 145, in update_one
return collection.update_one(query, {strategy: data}, upsert=upsert)
File "E:\Anaconda\lib\site-packages\pymongo\collection.py", line 1028, in update_one
self._update_retryable(
File "E:\Anaconda\lib\site-packages\pymongo\collection.py", line 877, in _update_retryable
return self.__database.client._retryable_write(
File "E:\Anaconda\lib\site-packages\pymongo\mongo_client.py", line 1552, in _retryable_write
return self._retry_with_session(retryable, func, s, None)
File "E:\Anaconda\lib\site-packages\pymongo\mongo_client.py", line 1438, in _retry_with_session
return self._retry_internal(retryable, func, session, bulk)
File "E:\Anaconda\lib\site-packages\pymongo\mongo_client.py", line 1470, in _retry_internal
return func(session, sock_info, retryable)
File "E:\Anaconda\lib\site-packages\pymongo\collection.py", line 869, in _update
return self._update(
File "E:\Anaconda\lib\site-packages\pymongo\collection.py", line 846, in _update
_check_write_command_response(result)
File "E:\Anaconda\lib\site-packages\pymongo\helpers.py", line 229, in _check_write_command_response
_raise_last_write_error(write_errors)
File "E:\Anaconda\lib\site-packages\pymongo\helpers.py", line 211, in _raise_last_write_error
raise WriteError(error.get("errmsg"), error.get("code"), error)
pymongo.errors.WriteError: The field 'customer' must be an array but is of type string in document {_id: ObjectId('645cf178f74445e7eff0458b')}, full error: {'index': 0, 'code': 2, 'errmsg': "The field 'customer' must be an array but is of type string in document {_id: ObjectId('645cf178f74445e7eff0458b')}"}
2023-05-16 16:54:46 - ERROR - [MainThread:create_tag(): 43] - error from creating new tag The field 'customer' must be an array but is of type string in document {_id: ObjectId('645cf178f74445e7eff0458b')}, full error: {'index': 0, 'code': 2, 'errmsg': "The field 'customer' must be an array but is of type string in document {_id: ObjectId('645cf178f74445e7eff0458b')}"}
2023-05-16 16:56:03 - INFO - [MainThread:tag_creation(): 52] - creating new tag api called
2023-05-16 16:56:03 - INFO - [MainThread:tag_details(): 34] - new tag created.....
2023-05-16 16:56:03 - INFO - [MainThread:create_tag(): 37] - creating new tag
2023-05-16 16:56:03 - ERROR - [MainThread:update_one(): 147] - The field 'customer' must be an array but is of type string in document {_id: ObjectId('645cf178f74445e7eff0458b')}, full error: {'index': 0, 'code': 2, 'errmsg': "The field 'customer' must be an array but is of type string in document {_id: ObjectId('645cf178f74445e7eff0458b')}"}
Traceback (most recent call last):
File "E:\Asset Manager V2\scripts\utils\mongo_tools\mongo_sync.py", line 145, in update_one
return collection.update_one(query, {strategy: data}, upsert=upsert)
File "E:\Anaconda\lib\site-packages\pymongo\collection.py", line 1028, in update_one
self._update_retryable(
File "E:\Anaconda\lib\site-packages\pymongo\collection.py", line 877, in _update_retryable
return self.__database.client._retryable_write(
File "E:\Anaconda\lib\site-packages\pymongo\mongo_client.py", line 1552, in _retryable_write
return self._retry_with_session(retryable, func, s, None)
File "E:\Anaconda\lib\site-packages\pymongo\mongo_client.py", line 1438, in _retry_with_session
return self._retry_internal(retryable, func, session, bulk)
File "E:\Anaconda\lib\site-packages\pymongo\mongo_client.py", line 1470, in _retry_internal
return func(session, sock_info, retryable)
File "E:\Anaconda\lib\site-packages\pymongo\collection.py", line 869, in _update
return self._update(
File "E:\Anaconda\lib\site-packages\pymongo\collection.py", line 846, in _update
_check_write_command_response(result)
File "E:\Anaconda\lib\site-packages\pymongo\helpers.py", line 229, in _check_write_command_response
_raise_last_write_error(write_errors)
File "E:\Anaconda\lib\site-packages\pymongo\helpers.py", line 211, in _raise_last_write_error
raise WriteError(error.get("errmsg"), error.get("code"), error)
pymongo.errors.WriteError: The field 'customer' must be an array but is of type string in document {_id: ObjectId('645cf178f74445e7eff0458b')}, full error: {'index': 0, 'code': 2, 'errmsg': "The field 'customer' must be an array but is of type string in document {_id: ObjectId('645cf178f74445e7eff0458b')}"}
2023-05-16 16:56:03 - ERROR - [MainThread:create_tag(): 43] - error from creating new tag The field 'customer' must be an array but is of type string in document {_id: ObjectId('645cf178f74445e7eff0458b')}, full error: {'index': 0, 'code': 2, 'errmsg': "The field 'customer' must be an array but is of type string in document {_id: ObjectId('645cf178f74445e7eff0458b')}"}
2023-05-16 16:56:54 - INFO - [MainThread:tag_creation(): 52] - creating new tag api called
2023-05-16 16:56:54 - INFO - [MainThread:tag_details(): 34] - new tag created.....
2023-05-16 16:56:54 - INFO - [MainThread:create_tag(): 37] - creating new tag
2023-05-16 16:56:54 - ERROR - [MainThread:create_tag(): 43] - error from creating new tag 'Devices' object has no attribute 'update'
2023-05-16 17:36:38 - INFO - [MainThread:tag_creation(): 52] - creating new tag api called
2023-05-16 17:36:38 - INFO - [MainThread:tag_details(): 34] - new tag created.....
2023-05-16 17:36:38 - INFO - [MainThread:create_tag(): 37] - creating new tag
2023-05-16 17:36:38 - ERROR - [MainThread:update_one(): 147] - The field 'customer' must be an array but is of type string in document {_id: ObjectId('645cf178f74445e7eff0458b')}, full error: {'index': 0, 'code': 2, 'errmsg': "The field 'customer' must be an array but is of type string in document {_id: ObjectId('645cf178f74445e7eff0458b')}"}
Traceback (most recent call last):
File "E:\Asset Manager V2\scripts\utils\mongo_tools\mongo_sync.py", line 145, in update_one
return collection.update_one(query, {strategy: data}, upsert=upsert)
File "E:\Anaconda\lib\site-packages\pymongo\collection.py", line 1028, in update_one
self._update_retryable(
File "E:\Anaconda\lib\site-packages\pymongo\collection.py", line 877, in _update_retryable
return self.__database.client._retryable_write(
File "E:\Anaconda\lib\site-packages\pymongo\mongo_client.py", line 1552, in _retryable_write
return self._retry_with_session(retryable, func, s, None)
File "E:\Anaconda\lib\site-packages\pymongo\mongo_client.py", line 1438, in _retry_with_session
return self._retry_internal(retryable, func, session, bulk)
File "E:\Anaconda\lib\site-packages\pymongo\mongo_client.py", line 1470, in _retry_internal
return func(session, sock_info, retryable)
File "E:\Anaconda\lib\site-packages\pymongo\collection.py", line 869, in _update
return self._update(
File "E:\Anaconda\lib\site-packages\pymongo\collection.py", line 846, in _update
_check_write_command_response(result)
File "E:\Anaconda\lib\site-packages\pymongo\helpers.py", line 229, in _check_write_command_response
_raise_last_write_error(write_errors)
File "E:\Anaconda\lib\site-packages\pymongo\helpers.py", line 211, in _raise_last_write_error
raise WriteError(error.get("errmsg"), error.get("code"), error)
pymongo.errors.WriteError: The field 'customer' must be an array but is of type string in document {_id: ObjectId('645cf178f74445e7eff0458b')}, full error: {'index': 0, 'code': 2, 'errmsg': "The field 'customer' must be an array but is of type string in document {_id: ObjectId('645cf178f74445e7eff0458b')}"}
2023-05-16 17:36:38 - ERROR - [MainThread:create_tag(): 43] - error from creating new tag The field 'customer' must be an array but is of type string in document {_id: ObjectId('645cf178f74445e7eff0458b')}, full error: {'index': 0, 'code': 2, 'errmsg': "The field 'customer' must be an array but is of type string in document {_id: ObjectId('645cf178f74445e7eff0458b')}"}
2023-05-16 17:37:25 - INFO - [MainThread:tag_creation(): 52] - creating new tag api called
2023-05-16 17:37:25 - INFO - [MainThread:tag_details(): 34] - new tag created.....
2023-05-16 17:37:25 - INFO - [MainThread:create_tag(): 37] - creating new tag
2023-05-16 17:37:25 - ERROR - [MainThread:update_one(): 147] - The field 'customer' must be an array but is of type string in document {_id: ObjectId('645cf178f74445e7eff0458b')}, full error: {'index': 0, 'code': 2, 'errmsg': "The field 'customer' must be an array but is of type string in document {_id: ObjectId('645cf178f74445e7eff0458b')}"}
Traceback (most recent call last):
File "E:\Asset Manager V2\scripts\utils\mongo_tools\mongo_sync.py", line 145, in update_one
return collection.update_one(query, {strategy: data}, upsert=upsert)
File "E:\Anaconda\lib\site-packages\pymongo\collection.py", line 1028, in update_one
self._update_retryable(
File "E:\Anaconda\lib\site-packages\pymongo\collection.py", line 877, in _update_retryable
return self.__database.client._retryable_write(
File "E:\Anaconda\lib\site-packages\pymongo\mongo_client.py", line 1552, in _retryable_write
return self._retry_with_session(retryable, func, s, None)
File "E:\Anaconda\lib\site-packages\pymongo\mongo_client.py", line 1438, in _retry_with_session
return self._retry_internal(retryable, func, session, bulk)
File "E:\Anaconda\lib\site-packages\pymongo\mongo_client.py", line 1470, in _retry_internal
return func(session, sock_info, retryable)
File "E:\Anaconda\lib\site-packages\pymongo\collection.py", line 869, in _update
return self._update(
File "E:\Anaconda\lib\site-packages\pymongo\collection.py", line 846, in _update
_check_write_command_response(result)
File "E:\Anaconda\lib\site-packages\pymongo\helpers.py", line 229, in _check_write_command_response
_raise_last_write_error(write_errors)
File "E:\Anaconda\lib\site-packages\pymongo\helpers.py", line 211, in _raise_last_write_error
raise WriteError(error.get("errmsg"), error.get("code"), error)
pymongo.errors.WriteError: The field 'customer' must be an array but is of type string in document {_id: ObjectId('645cf178f74445e7eff0458b')}, full error: {'index': 0, 'code': 2, 'errmsg': "The field 'customer' must be an array but is of type string in document {_id: ObjectId('645cf178f74445e7eff0458b')}"}
2023-05-16 17:37:25 - ERROR - [MainThread:create_tag(): 43] - error from creating new tag The field 'customer' must be an array but is of type string in document {_id: ObjectId('645cf178f74445e7eff0458b')}, full error: {'index': 0, 'code': 2, 'errmsg': "The field 'customer' must be an array but is of type string in document {_id: ObjectId('645cf178f74445e7eff0458b')}"}
2023-05-16 18:10:43 - INFO - [MainThread:<module>(): 17] - ****Starting AssetManagerV2 v.2.0***
2023-05-16 18:10:43 - INFO - [MainThread:<module>(): 44] - App Starting at 127.0.0.1:8000 with 1 workers.
2023-05-16 18:12:02 - INFO - [MainThread:<module>(): 17] - ****Starting AssetManagerV2 v.2.0***
2023-05-16 18:12:02 - INFO - [MainThread:<module>(): 44] - App Starting at 127.0.0.1:8000 with 1 workers.
2023-05-16 18:12:22 - INFO - [MainThread:tag_creation(): 52] - creating new tag api called
2023-05-16 18:12:22 - INFO - [MainThread:tag_details(): 34] - new tag created.....
2023-05-16 18:12:22 - INFO - [MainThread:create_tag(): 37] - creating new tag
2023-05-16 18:12:22 - ERROR - [MainThread:update_one(): 147] - The field 'customer' must be an array but is of type string in document {_id: ObjectId('645cf178f74445e7eff0458b')}, full error: {'index': 0, 'code': 2, 'errmsg': "The field 'customer' must be an array but is of type string in document {_id: ObjectId('645cf178f74445e7eff0458b')}"}
Traceback (most recent call last):
File "E:\Asset Manager V2\scripts\utils\mongo_tools\mongo_sync.py", line 145, in update_one
return collection.update_one(query, {strategy: data}, upsert=upsert)
File "E:\Anaconda\lib\site-packages\pymongo\collection.py", line 1028, in update_one
self._update_retryable(
File "E:\Anaconda\lib\site-packages\pymongo\collection.py", line 877, in _update_retryable
return self.__database.client._retryable_write(
File "E:\Anaconda\lib\site-packages\pymongo\mongo_client.py", line 1552, in _retryable_write
return self._retry_with_session(retryable, func, s, None)
File "E:\Anaconda\lib\site-packages\pymongo\mongo_client.py", line 1438, in _retry_with_session
return self._retry_internal(retryable, func, session, bulk)
File "E:\Anaconda\lib\site-packages\pymongo\mongo_client.py", line 1470, in _retry_internal
return func(session, sock_info, retryable)
File "E:\Anaconda\lib\site-packages\pymongo\collection.py", line 869, in _update
return self._update(
File "E:\Anaconda\lib\site-packages\pymongo\collection.py", line 846, in _update
_check_write_command_response(result)
File "E:\Anaconda\lib\site-packages\pymongo\helpers.py", line 229, in _check_write_command_response
_raise_last_write_error(write_errors)
File "E:\Anaconda\lib\site-packages\pymongo\helpers.py", line 211, in _raise_last_write_error
raise WriteError(error.get("errmsg"), error.get("code"), error)
pymongo.errors.WriteError: The field 'customer' must be an array but is of type string in document {_id: ObjectId('645cf178f74445e7eff0458b')}, full error: {'index': 0, 'code': 2, 'errmsg': "The field 'customer' must be an array but is of type string in document {_id: ObjectId('645cf178f74445e7eff0458b')}"}
2023-05-16 18:12:22 - ERROR - [MainThread:create_tag(): 43] - error from creating new tag The field 'customer' must be an array but is of type string in document {_id: ObjectId('645cf178f74445e7eff0458b')}, full error: {'index': 0, 'code': 2, 'errmsg': "The field 'customer' must be an array but is of type string in document {_id: ObjectId('645cf178f74445e7eff0458b')}"}
2023-05-16 22:56:03 - INFO - [MainThread:<module>(): 17] - ****Starting AssetManagerV2 v.2.0***
2023-05-16 22:56:03 - INFO - [MainThread:<module>(): 44] - App Starting at 127.0.0.1:8000 with 1 workers.
2023-05-16 22:56:42 - INFO - [MainThread:download_file_details(): 40] - download file details api called
2023-05-16 22:56:42 - INFO - [MainThread:store_file_details(): 60] - new file added into db
2023-05-16 22:56:42 - INFO - [MainThread:store_file_details(): 22] - new file added
2023-05-16 22:56:42 - INFO - [MainThread:store_file_details(): 65] - file details inserted
2023-05-16 23:07:09 - INFO - [MainThread:<module>(): 17] - ****Starting AssetManagerV2 v.2.0***
2023-05-16 23:07:09 - INFO - [MainThread:<module>(): 44] - App Starting at 127.0.0.1:8000 with 1 workers.
2023-05-16 23:07:37 - INFO - [MainThread:download_file_details(): 40] - download file details api called
2023-05-16 23:07:37 - INFO - [MainThread:store_file_details(): 60] - new file added into db
2023-05-16 23:07:37 - ERROR - [MainThread:store_file_details(): 33] - error while storing file details 'dict' object has no attribute 'file_name'
...@@ -3,6 +3,7 @@ class _APIEndPoints: ...@@ -3,6 +3,7 @@ class _APIEndPoints:
api_create: str = "/create" api_create: str = "/create"
db_test: str = "/update" db_test: str = "/update"
create_tag: str = "/create_tag" create_tag: str = "/create_tag"
download_file: str = "/download_file"
APIEndPoints = _APIEndPoints() APIEndPoints = _APIEndPoints()
...@@ -8,3 +8,4 @@ class DatabaseConstants: ...@@ -8,3 +8,4 @@ class DatabaseConstants:
# Collections # Collections
collection = "test" collection = "test"
download_file_details = "download_file_details"
from scripts.database.mongodb.asset_manager.collections.device import Devices from scripts.database.mongodb.asset_manager.collections.device import Devices
from scripts.database.mongodb.asset_manager.collections.download_file import FileDetails
from scripts.logging.logger import logger from scripts.logging.logger import logger
obj = Devices() obj = Devices()
file_obj = FileDetails()
class AssetHandler: class AssetHandler:
...@@ -28,12 +30,40 @@ class AssetHandler: ...@@ -28,12 +30,40 @@ class AssetHandler:
return None return None
@staticmethod @staticmethod
def fetch_tag_details(details): def tag_details(details):
try: try:
logger.info("fetching the tag details.....") logger.info("new tag created.....")
# fetching the tag details # fetching the tag details
# Construct the filter to match the document with the given _id
fetch = {"mac_address": details.mac}
data = {"country": details.country,
"state": details.state,
"vendor": details.vendor,
"device": details.device,
"customer": details.customer
}
db_update = obj.create_tag(fetch, data)
if db_update:
logger.info("new tag created")
else:
return None
except Exception as e: except Exception as e:
logger.error(f"error from handler {e}") logger.error(f"error from handler {e}")
@staticmethod
def store_file_details(file_data):
try:
logger.info("new file added into db")
data = {"file_name": file_data.file_name,
"value": file_data.link}
file_store = file_obj.store_file_details(data)
if file_store:
logger.info("file details inserted")
else:
return None
except Exception as e:
logger.error(f"error in storing the file detalis {e}")
...@@ -4,7 +4,7 @@ from scripts.constants.db_constants import DatabaseConstants ...@@ -4,7 +4,7 @@ from scripts.constants.db_constants import DatabaseConstants
from scripts.database.mongodb import CollectionBaseClass, mongo_client from scripts.database.mongodb import CollectionBaseClass, mongo_client
from scripts.database.mongodb.asset_manager import database from scripts.database.mongodb.asset_manager import database
from scripts.logging.logger import logger from scripts.logging.logger import logger
from scripts.schemas.tag_schema import TestUpdate
from scripts.utils.mongo_utils import MongoStageCreator from scripts.utils.mongo_utils import MongoStageCreator
collection_name = DatabaseConstants.collection collection_name = DatabaseConstants.collection
......
from scripts.constants.db_constants import DatabaseConstants
from scripts.database.mongodb import CollectionBaseClass, mongo_client
from scripts.database.mongodb.asset_manager import database
from scripts.logging.logger import logger
from scripts.utils.mongo_utils import MongoStageCreator
collection_name = DatabaseConstants.download_file_details
mongo_stage_creator = MongoStageCreator()
class FileDetails(CollectionBaseClass):
def __init__(self):
super().__init__(
mongo_client,
database=database,
collection=collection_name
)
def fetch_file_name(self,file_data):
try:
fetch_file_name = self.find_one(file_data.file_name)
if fetch_file_name is None:
logger.info("")
def store_file_details(self, file_data):
try:
if fetch_file_name is None:
logger.info("new file added")
result = self.insert_one(file_data)
if result:
return {"file details added"}
else:
return None
else:
return {f"{file_data.file_name} already added"}
except Exception as e:
logger.error(f"error while storing file details {e}")
return None
class ILensErrors(Exception):
"""Generic iLens Error"""
class AuthenticationError(ILensErrors):
pass
class ErrorMessages:
UNKNOWN_ERROR = "Unknown Error Occurred"
OP_FAILED = "Operation failed"
RES_FAILED = "Failed To get Details from remote devices"
# Authorization Errors
DEVICE_CREATION_FAILED = "Device creation failed. Check your inputs or contact support."
INVALID_DEVICE_ID = "Device ID is invalid, please check input."
class DeviceCreationError(ILensErrors):
"""
Raises when device creation or registration fails
"""
class InvalidDeviceIDError(ILensErrors):
"""
Raise when device ID is invalid or not found
"""
from typing import Any, Optional
from pydantic import BaseModel
class DefaultResponse(BaseModel):
status: str = "success"
message: Optional[str]
data: Optional[Any]
class DefaultFailureResponse(DefaultResponse):
status: str = "failed"
error: Any
from pydantic import BaseModel from pydantic import BaseModel
class TestUpdate(BaseModel): class Tag(BaseModel):
mac: str mac: str
country: str country: str
state: str state: str
vendor: str vendor: str
device: str
customer: str customer: str
class File(BaseModel):
file_name: str
link: str
...@@ -4,43 +4,41 @@ from fastapi import APIRouter, Request ...@@ -4,43 +4,41 @@ from fastapi import APIRouter, Request
from scripts.constants.api import APIEndPoints from scripts.constants.api import APIEndPoints
from scripts.core.handlers.device_handler import AssetHandler from scripts.core.handlers.device_handler import AssetHandler
from scripts.database.mongodb.asset_manager.collections.device import Devices from scripts.database.mongodb.asset_manager.collections.device import Devices
from scripts.errors import ErrorMessages
from scripts.logging.logger import logger from scripts.logging.logger import logger
from scripts.schemas.tag_schema import TestUpdate from scripts.schemas.deafult_responses import DefaultResponse
from scripts.schemas.tag_schema import Tag, File
router = APIRouter() router = APIRouter()
Asset_obj = AssetHandler() Asset_obj = AssetHandler()
@router.post(APIEndPoints.api_create, tags=["tag api"]) @router.get(APIEndPoints.root, tags=["Asset Manager"])
async def store_tag(): async def root():
logger.info("tag of a device is stored")
try: try:
# payload=await response.body() return {"API running"}
# status=
return {"data": "api running successfully"}
except Exception as e: except Exception as e:
logger.error(f"error from asset_management") logger.error(f"root api failed due to {e}")
return DefaultResponse(error=ErrorMessages.OP_FAILED)
@router.post(APIEndPoints.db_test, tags=["update test"])
async def update_db(data: TestUpdate):
try:
logger.info("update method called")
print(data)
Asset_obj.update_db(data)
return {"data": "updated"}
except Exception as e:
logger.error(f"error from asset management.py {e}")
return None
@router.post(APIEndPoints.create_tag, tags=["creating tags"]) @router.post(APIEndPoints.create_tag, tags=["creating tags"])
async def tag_creation(): async def tag_creation(payload: Tag):
try: try:
logger.info("creating new tag api called") logger.info("creating new tag api called")
Asset_obj.fetch_tag_details() Asset_obj.tag_details(payload)
return {"data": "tag created"} return {"data": "tag created"}
except Exception as e: except Exception as e:
logger.error(f"error from tag creation api {e}") logger.error(f"error from tag creation api {e}")
return None return None
@router.post(APIEndPoints.download_file, tags=["download file"])
async def download_file_details(file_details: File):
try:
logger.info("download file details api called")
Asset_obj.store_file_details(file_details)
return {"data": "file details stored"}
except Exception as e:
logger.error(f"error from download file details api")
...@@ -127,7 +127,7 @@ class MongoCollectionBaseClass: ...@@ -127,7 +127,7 @@ class MongoCollectionBaseClass:
query: dict, query: dict,
data: dict, data: dict,
upsert: bool = False, upsert: bool = False,
strategy: str = "$set", strategy: str = "$push",
) -> UpdateResult: ) -> UpdateResult:
""" """
......
from pymongo import MongoClient
# Connect to MongoDB
client = MongoClient('mongodb://localhost:27017')
db = client['asset_manager']
collection = db['test']
fetch = {"mac_address": "b8:27:eb:67:bd:3d"}
# New field values
new_tag = {
"country": "india",
"state": "kerala",
"vendor": "seimens",
"device": "MP201A",
"customer": "Dalmia"
}
# Add the new field to the "tags" array in all documents
collection.update_many(fetch, {"$push": {"tags": new_tag}}
)
# Close the MongoDB connection
client.close()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment