azure ml update service erro AttributeError: AttributeError: 'str' object has no attribute 'id' - azure-machine-learning-studio

I am tying to update existing webservice using new Azure ML package
Its failing with error - AttributeError: 'str' object has no attribute 'id'
"/opt/hostedtoolcache/Python/3.6.14/x64/lib/python3.6/site-packages/azureml/core/webservice/aks.py", line 678, in update
patch_list.append({'op': 'replace', 'path': '/imageId', 'value': image.id})
AttributeError: 'str' object has no attribute 'id'
Here is the script I am using -
ws = Workspace.get(
name=workspace_name,
subscription_id=subscription_id,
resource_group=resource_group,
auth=cli_auth)
model = Model.register(model_path = model_path,
model_name = model_name,
#tags = {"key": "1"},
description = model_description,
workspace = ws)
image_config = ContainerImage.image_configuration(execution_script="score.py",
runtime="python",
conda_file="packagesenv.yml")
image = 'testazureml'
service_name = 'testazureml'
# Retrieve existing service
service = Webservice(name = service_name, workspace = ws)
print(service)
service.update(image,'image.id')
please help
I have been trying with different methods
as - 'id', 'image_id'
its still failing

Here is Sample to Register and Deploy.
Document to Update a deployed web service: https://learn.microsoft.com/en-us/azure/machine-learning/how-to-deploy-update-web-service

This worked for me. above script was failing to get image details -
ws = Workspace.get(
name=workspace_name,
subscription_id=subscription_id,
resource_group=resource_group,
auth=cli_auth)
model = Model.register(model_path = model_path,
model_name = model_name,
#tags = {"key": "1"},
description = model_description,
workspace = ws)
image_config = ContainerImage.image_configuration(execution_script="score.py",
runtime="python",
conda_file="packagesenv.yml")
image = 'testazureml'
service_name = 'testazureml'
new_image = Image(ws, image)
# Retrieve existing service
service = Webservice(name = service_name, workspace = ws)
print(service)
service.update(image=new_image)
service.wait_for_deployment(show_output=True)
print(service.state)

Related

Get relative object after creating it in Async SQL Alchemy

I have model:
`class User(Base):
tablename = 'user'
id = Column(Integer, Sequence('id'), primary_key=True)
name = Column(String(50), nullable=False)
coffee_id = Column(Integer, ForeignKey('coffee.id'))
coffee = relationship('Coffee', backref='users')`
in SQL Alchemy I create object:
new_user = User(name="user", coffee_id=1) async with session.begin(): session.add(new_user)
If i am trying get new_user.coffee i get exception, that object is not downloaded.
Of course i can do:
user_with_coffee = select(User) \ .filter_by(id=new_user.id) \ .options(selectinload(User.coffee)) new_user = await session.execute(user_with_coffee)
But maybe i can add some parameter in add method of session or something else to avoid second query in db ?

Error "object 'res' not found" when trying to run mixpanelGetProfiles()

Tried running the following code to query MixPanel API using RMixpanel package. However, I get the following error:
Error in mixpanelGetData(account, "engage/", args, data = TRUE,
verbose = verbose) : object 'res' not found
require(RMixpanel)
account = mixpanelCreateAccount('hidden',
token = 'hidden',
key = 'hidden',
secret = 'hidden')
profiles = mixpanelGetProfiles(account, select = c("Group Count", "DM
Count", "Relationship Count","Lifetime members added"),maxPage =
100,verbose = TRUE)
Above code should query the Mixpanel Formatted Data Export API. Couldn't find anyone else talking about this issue.

How to get datastore entity urlsafe from dataflow

Is there anyway to get datastore entity legacy urlsafe in dataflow?
I've tried some method but all failed...
Direct encode
base64.urlsafe_b64encode(key.SerializeToString()).strip(b'=')
=> not the same compared with appengine
import google.cloud.datastore.key
=> seems conflict with dataflow datastoreio?
Copy _app_engine_key_pb2.py from google.cloud.datastore and use it just like to_legacy_urlsafe() source code
elements = []
for part in key.path:
element_kwargs = {'type': part.kind}
if part.id:
element_kwargs['id'] = part.id
elif part.name:
element_kwargs['name'] = part.name
element = _app_engine_key_pb2.Path.Element(**element_kwargs)
elements.append(element)
legacy_path = _app_engine_key_pb2.Path(element=elements)
reference = _app_engine_key_pb2.Reference(
app=key.partition_id.project_id,
path=legacy_path,
name_space=key.partition_id.namespace_id
)
raw_bytes = reference.SerializeToString()
urlsafe = base64.urlsafe_b64encode(raw_bytes).strip(b'=')
=> still not the same compared with appengine...
The ndb code has:
urlsafe = base64.b64encode(self.reference().Encode())
return urlsafe.rstrip('=').replace('+', '-').replace('/', '_')
So you should get the same results with:
urlsafe = base64.b64encode(key.SerializeToString())
return urlsafe.rstrip('=').replace('+', '-').replace('/', '_')
Are you using ndb or the db library? The to_legacy_urlsafe() function you found seems to match the db library.

Mongoengine serialize dictionary (with nested dicts)?

I've created a dictionary from an Uploaded file in Django.
This dictionary has a nested list of dictionaries:
file = {"name": "filename", "sections": [{"section_name": "string", "lines": [{line_number: 0, "line"; "data"}]}], "etc": "etc"}
The model represents the dictionaries depth too.
class Line(EmbeddedDocument):
line_number = IntField()
line = StringField()
definition = ReferenceField(Definition)
class Section(EmbeddedDocument):
section_name = StringField()
lines = EmbeddedDocumentListField(Line))
class File(Document):
name = StringField()
sections = EmbeddedDocumentListField(Section))
created_on = DateTimeField()
created_by = StringField()
modified_on = DateTimeField()
modified_by = StringField()
In the POST I have the following to chop the file up into the above Dict (the file is a simple text file):
file= {}
with open(os.path.join(path, filename + ".txt"), 'r') as temp_file:
filelines = temp_file.readlines()
sections = []
section = {}
lines = []
for i, l in enumerate(filelines):
if i == 0:
section["section_name"] = "Top"
elif '*' in l:
if l.index('*') == 0 and '*' not in lines[len(lines) - 2"line"]:
section["lines"] = lines
lines = []
sections.append(section)
section = dict()
section["section_name"] = filelines[i + 1][1:-2]
line = {"line_number": i + 1, "line": l}
lines.append(line)
section['lines'] = lines
sections.append(section)
file["name"] = filename
file["sections"] = sections
I will tidy this up eventually.
Once the dict has been made how do I serialise it using the serializer?
Is it possible to insert this into a serializer?
If not how can I get it all into the database with validation?
I've tried json.dumps() and JsonRequst() then putting them in data= for the serializer but get Unable to get repr for <class '....'>
I'm pretty new to Django and MongoDB so if you need more info I can provide :)
Thanks!
Update
Change the model's List Fields to EmbeddedDocumentListField as suggest in the answer.
Answered
Thanks to Boris' suggestion below it pointed me to an error I wasn't getting initially. I had a typo and passing the dict directly into FileSerializer(data=file) works like a charm! :)
James!
The easiest way to validate that your incoming JSONs adhere to the Mongoengine Documents schema that you've specified is to use DRF-Mongoengine's DocumentSerializer.
Basically, what you need to do is create a serializer
serializers.py
import rest_framework_mongoengine
class FileSerializer(rest_framework_mongoengine.DocumentSerializer):
class Meta:
fields = '__all__'
model = File
Then you need a view or viewset that makes use of this Serializer to respond to GET/POST/PUT/DELETE requests.
views.py
from rest_framework_mongoengine import viewsets
class FileViewSet(viewsets.ModelViewSet):
lookup_field = 'id'
serializer_class = FileSerializer
def get_queryset(self):
return File.objects.all()
and register this viewset with a router
urls.py
from rest_framework import routers
# this is DRF router for REST API viewsets
router = routers.DefaultRouter()
# register REST API endpoints with DRF router
router.register(r'file', FileViewSet, r"file")
I'd also recommend using EmbeddedDocumentListField instead of ListField(EmbeddedDocumentField(Section)) - it has additional methods.

Sage CRM - There is method to retrieve the ID on the recently created record when using CRM.CreateRecord object?

Given this code:
var NewComm = CRM.CreateRecord("Communication");
NewComm("Comm_ChannelId") = Request.Form("chanId");
NewComm("Comm_Type") = "Appointment";
NewComm("Comm_DateTime") = Request.Form("initialHour");
NewComm("Comm_Status") = "Pending";
NewComm("Comm_Priority") = "Normal";
NewComm("Comm_Action") = "Meeting";
NewComm("Comm_SecTerr") = Request.Form("secTerr");
NewComm("Comm_Subject") = "No Subject";
NewComm("Comm_Note") = "No notes";
NewComm.SaveChanges();
There is a method of the CreateRecord Object to retrieve the ID of the recently created record?
Once you have created the new record, the Id becomes available in the object. Using your example above, you can simply get the Id with this code:
NewComm.SaveChanges();
var CommId = NewComm("Comm_CommunicationId");
This applies to any record type with the same method.
Six Ticks Support

Resources